Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb Site ManagementScripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 22nd, 2008, 10:56 AM
acidedge2004 acidedge2004 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 122 acidedge2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 42 m 25 sec
Reputation Power: 1
Batch file: passing a string variable to sql script results in truncation

Hi, I have a batch file that takes variables from the cmd and passes them by sqlcmd to an SQL script. When I pass the variable 'MikeTestList' the script runs as expected with no problems. When I passed 'BulkTransferTest' I got an error message, 'The string or binary data will be truncated'.

Some testing has shown that I get the error when the string is anything above 12 characters. Is there a limit to the length of a string you can pass using sqlcmd from a batch file? Is there any way around it?

Also, if I have a space in the string, it only passes the string up to the space. I have tried to fill it with a '%' which then gets passed as is, so the % stays in place through out the script. Can you solve this too?!

Any help will be appreciated!

Code:
@REM BulkTransfer.bat
@REM ----------------------------------------------------------
@REM This batch file takes 5 parameters. 
@REM 1 The server name
@REM 2 The Old Site Name
@REM 3 The New Site Name
@REM 4 The Termination Date of the old site.
@REM 5 The List containing patients to be transferred


:begin
@ECHO OFF
ECHO. 
Sqlcmd -S "%1" -E -h -1 -Q "set nocount on select'You are about to transfer patients from ' +(SELECT rtrim(ltrim(PRACTICE_NAME)) FROM SITE_DETAILS WHERE ID =%2)+' to '+(select rtrim(ltrim(PRACTICE_NAME)) FROM EMISSYSTEM..SITE_DETAILS WHERE ID = %3)" 
ECHO. 
SET /P runscript="Do you wish to run the transfer script? (Y/N) "
if %runscript%==y goto run
if %runscript%==Y goto run
if %runscript%==n goto end
if %runscript%==N goto end
goto begin

:run
Set FileDate=%date:/=%
ECHO.
ECHO Log has been saved to %CD%
ECHO. 
sqlcmd -S "%1" -v oldsite = "%2" -v newsite = "%3" -v terminationdate = "%4" -v oldlist = "%5" -E -i "BulkTransferScript.sql" -o "LogFile_%2_to_%3_%Filedate%.CSV"
:END

Last edited by acidedge2004 : May 22nd, 2008 at 11:13 AM.

Reply With Quote
  #2  
Old May 23rd, 2008, 09:50 AM
bullet's Avatar
bullet bullet is offline
Java Junkie
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jan 2004
Location: Mobile, Alabama
Posts: 3,267 bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level)bullet User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 13 h 26 m 35 sec
Reputation Power: 307
Send a message via ICQ to bullet Send a message via AIM to bullet Send a message via MSN to bullet
Does the table in the database have a column that you're trying to insert into that has a length of 12 on it?

Also when you have a string with a space in it, if you put quotes around the string, does it work?

Reply With Quote
  #3  
Old May 23rd, 2008, 03:05 PM
acidedge2004 acidedge2004 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 122 acidedge2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 42 m 25 sec
Reputation Power: 1
well the field does not have a length of 12 on it, it can accept more than that. The list that the string is naming is longer than that which is why I discovered the problem in the first place. The field has a length of 255 on it.

As for surrounding it in quotes, it is passed as 'List' and the variable is surrounded by "" in the dos script.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Batch file: passing a string variable to sql script results in truncation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway