Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sqlcmd truncated feild

Author  Topic 

nbritton
Starting Member

22 Posts

Posted - 2012-05-09 : 17:29:18
When i run a simple query for six columns from two tables doing a inner join, i get the first column truncted as follows:

0xB2D3F86F840CFA42

it should be
0xB2D3F86F840CFA428B1061F73B64951D

here is the query:

sqlcmd -S server\instance -U username -P password -d database -s "|" -W -h-1 -Q "SELECT usp_contact.contact_uuid, c_cm_id1, c_cm_id2, c_cm_id3, c_cm_id4, ca_contact.last_name FROM ca_contact INNER JOIN usp_contact ON ca_contact.contact_uuid = usp_contact.contact_uuid WHERE ca_contact.inactive = 0 AND ca_contact.contact_type = '2308' AND (usp_contact.c_cm_id2 <> '30427950' or usp_contact.c_cm_id2 is null ) and usp_contact.contact_uuid not in (0x096A060435922A428B357F4DB03A6B99,0x136FDC787B472C43998F95D66EA434F0,0xF0C6F9375754C347B09AB19E4FB656A7)"

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-09 : 18:31:57
Run this query through sqlcmd and let us know:

SELECT TOP 1000 contact_uuid
FROM usp_contact
WHERE contact_uuid not in (0x096A060435922A428B357F4DB03A6B99,0x136FDC787B472C43998F95D66EA434F0,0xF0C6F9375754C347B09AB19E4FB656A7)

And I assume your query returns fine through SSMS?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

nbritton
Starting Member

22 Posts

Posted - 2012-05-10 : 09:22:12
Ok i ran the query with sqlcmd and found that all the output was still truncated. Below is a sample of what was returned. Your assumption is correct with SSMS it runs as expected.

0x05E1A23F5556D64F
0x05E2D669123C004A
0x05E5CDA74005B649
0x05E66854CB36ED47
0x05E6B80055D2A64A
0x05E73578136AAA44
0x05E7C7E62B33124B
0x05E7DD88748C2F49
0x05E884CAFB36DD48
0x05E8C016957E114A
0x05EAC8E8B96B884F
0x05EB2C245D177043
0x05EB74EB1A000B4A
0x05EBE46ECA428247
0x05EC3453A1A83C47
0x05EC66EC87D9794B
0x05EDBC59FC862645
0x05EE01AD884D9749
0x05F0E9A8F9FD0B47
0x05F1A942501C564A
0x05F1AAF40B7EA34B
0x05F4AE1489934046
0x05F5593EC1FBCD46
0x05F5A5706941F347
0x05F6D948971B5A42
0x05F8841DB5332944
0x05F9E3CD8BBEC647
0x05FB93B19663624D
0x05FBDEF74A869647
0x05FF09C532F98B44
0x06001FEDA48BE74F
0x0605D9E90ECDA64B
0x0607F348F0EA5C43
0x0608A5281254F04A
0x0609EE6CEAC33D44
0x060AD18900C1054F
0x060B569CFF332044
0x060C69C9FA7EEF49
0x060CA5B2572ED34B
0x060E30673F2AAF41
0x060E5B1D4BF0E64A
0x060F21F5636E4241
0x060F4E60AC299A4A
0x06101D93F9A5DA45
0x0611A4A0BF00ED41
0x0614480B6468DE49
0x06152ACA695D5E40
0x061576A4842A024C
0x061622B86E6BD741
0x061744A327DFF64B
0x061DAE09AF5A3F48
0x06223261008E3044
0x0622D2B15444F643
0x0623216A94E27446
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-10 : 18:30:08
What data type is that column? I'd like to run a test.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

nbritton
Starting Member

22 Posts

Posted - 2012-05-11 : 11:24:16
binary
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-11 : 14:00:02
It seems to be a bug with sqlcmd as I can easily reproduce it. I don't have a suggestion except to contact Microsoft.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

nbritton
Starting Member

22 Posts

Posted - 2012-05-11 : 14:08:31
ok thanks. I thought it was something i was doing.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-11 : 14:40:43
Actually my suggestion is to throw your query into a view and then bcp out the view. I have not tested it, but that might work.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

nbritton
Starting Member

22 Posts

Posted - 2012-05-11 : 14:59:20
I did find that if i cast it as binary i get all except the last two chars. I have requested our db team open with microsoft, so we will see what happens. When i find an anwser i will post it here. I have also tried powershell but it also converts the data someway.
Go to Top of Page

nbritton
Starting Member

22 Posts

Posted - 2012-05-11 : 15:58:23
I chagned to osql, used a -w500 to fix a wrapping problem and it worked as needed. Thank you much for your help.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-11 : 16:01:34
Glad you found a workaround!

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -