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.
| Author |
Topic |
|
Trent
Starting Member
39 Posts |
Posted - 2005-10-10 : 15:23:39
|
| I'm declaring a variable as char(5), yet once in a while it will take a number like '00101' and convert it to '101', sometimes it will leave it as '00101'.Any ideas? |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-10-10 : 16:22:09
|
quote: Originally posted by Trent yet once in a while it will take a number like '00101' and convert it to '101'
That statement is false.DECLARE @x char(5)SELECT @x = '00101'SELECT @x Read the hint link below and follow the directions in it.Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
Trent
Starting Member
39 Posts |
Posted - 2005-10-10 : 16:33:28
|
| I found that it will correctly return the leading zeros, unless the select is contained in an exec('') statement. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-10-11 : 05:26:44
|
| I reckon that somewhere the value is getting cast [implicitly or otherwise] to a numericPerhaps in the EXEC you are processing the value in some way and NOT surrounding it with single quotes?Kristen |
 |
|
|
Trent
Starting Member
39 Posts |
Posted - 2005-10-11 : 09:19:49
|
| RESOLVEDStupid mistake, that's what it was.This was part of the code in the exec statement:Select '+@Serial+' from tSpecificsShould have been:Select '''+@Serial+''' from tSpecificsThank you all for your help |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|