Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 3rd, 2007, 03:52 AM
Authorized User
 
Join Date: Dec 2006
Location: chennai, tn, India.
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
Reply With Quote
  #2 (permalink)  
Old January 3rd, 2007, 04:30 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
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

Reply With Quote
  #3 (permalink)  
Old January 4th, 2007, 08:50 AM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
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
Reply With Quote
  #4 (permalink)  
Old January 4th, 2007, 11:25 AM
Authorized User
 
Join Date: May 2006
Location: Bangalore, , India.
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 ...




Reply With Quote
  #5 (permalink)  
Old January 5th, 2007, 11:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:26 AM.


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