Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 3rd, 2007, 03:52 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic Query - String truncation...

Hi all,

DECLARE @SQL varchar(2000)
SELECT @SQL = 'CREATE TABLE ' + @TABLENAME + ...........
EXEC @SQL
SELECT @SQL = 'echo ' + @SQL + ' > D:\SQL1.txt'
SELECT @SQL 'SQL'
EXEC master..xp_cmdshell @SQL

I build the dynamic Query and that Query output should be finally written to the file system. I used the above program to write it to the file system. The problem here is only part of the string is written and when i printed @SQL variable it outputs only the part of the String. (Dynamic query is stored in @SQL variable), but my dynamic execution of table structure goes fine and the table is created successfully in the database.

Pls help me out in resolving it.






Chandru
__________________
Thanks,
Chandra
 
Old January 3rd, 2007, 04:30 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not sure if this is the problem but this may help, something to try. You may just be getting extra blanks at the end that your not seeing. To troubleshoot you may want to test the length of fields to see if they are as long/short as you think they are.

DECLARE @SQL varchar(2000)
SELECT @SQL = 'CREATE TABLE ' + rtrim(@TABLENAME) + rtrim(...........)
EXEC @SQL
SELECT @SQL = 'echo ' + rtrim(@SQL) + ' > D:\SQL1.txt'
SELECT @SQL 'SQL'
EXEC master..xp_cmdshell @SQL

 
Old January 4th, 2007, 08:50 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

If you a printing the string in Query Analyzer, the default setting for each column is something like 255 characters. If you want to see it all, you'll need to select [TOOLS][OPTIONS], select the [RESULTS] tab, and set the [Maximum Characters Per Column] setting to something larger. I set mine to 8,060 and leave it.

--Jeff Moden
 
Old January 4th, 2007, 11:25 AM
Authorized User
 
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to manudutt
Default

Chandru your problem is only due to enter key character (char(13)), if you use any return key withing @SQL string , only that part of string that comes before enter (char(13)) is taken by SELECT statement and this way '> D:\sql.txt' is also trimmed out ..

if there is no return key in @SQL string , your CREATE statement will be logged to system file easily ...




 
Old January 5th, 2007, 11:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by manudutt
 Chandru your problem is only due to enter key character (char(13)), if you use any return key withing @SQL string , only that part of string that comes before enter (char(13)) is taken by SELECT statement and this way '> D:\sql.txt' is also trimmed out ..

if there is no return key in @SQL string , your CREATE statement will be logged to system file easily ...
manudutt, You are wrong. That is not the case...

Try this out in your system... and open sql.txt file.
Code:
DECLARE @TableName varchar(100)
DECLARE @SQL varchar(2000)
SET @TableName = 'testtbl'
SET @SQL = 'CREATE TABLE ' + @TABLENAME + char(13) + '(' + char(13) + 'col1 int' + char(13) + ')'
print @SQL
SELECT @SQL = 'echo ' + @SQL + ' > C:\SQL1.txt'
SELECT @SQL 'SQL'
EXEC master..xp_cmdshell @SQL
carumuga,

Unless you post the complete code, we wouldn't be able to point out what you are missing. How about posting the complete code here?

Cheers

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
string to x-path - EXSLT - dynamic functions Geierwally XSLT 1 July 12th, 2007 10:35 AM
Dynamic connection string from ASP page jayaraj Classic ASP Databases 2 July 12th, 2004 07:44 AM
Dynamic connection string from ASP jayaraj General .NET 1 July 12th, 2004 04:19 AM
Setting Dynamic Connection String jayaraj General .NET 1 July 9th, 2004 08:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.