Author |
Topic |
skybvi
Posting Yak Master
193 Posts |
Posted - 2011-10-10 : 11:13:21
|
hI, I have a column in a table where the values are all digits (4-14 numbers)THe values are :- 200387378385934563409880000485034856929142300000000004343From these i just want to select the values in which the last 5 digits are all 0In the above values last 3 values have 5 zeros but i want only that in whcih the last 5 digits are zeros irrelavent of otehr digits.For ex. in the above values i want 6929142300000 ONLY.How to get those values.Regards,SushantDBAWest Indies |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-10-10 : 11:18:07
|
Your example data shows leading zeroes so I assume the datatype is varchar or so.where right(YourNumbersColumn,5) = '00000' No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2011-10-10 : 11:26:22
|
datatype is nvarchar(14).Regards,SushantDBAWest Indies |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2011-10-10 : 11:54:33
|
@WEBFREDThe sql you provided doesn't work :(I am getting values like '1660000000'I want just the values where last 5 digits are zeros.Regards,SushantDBAWest Indies |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-10-10 : 12:00:56
|
where fld like '%[1-9]00000'or maybewhere fld like '%[^0]00000'==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2011-10-10 : 12:18:36
|
It worked.Thanks nigelrivettand webfred for your help.Regards,SushantDBAWest Indies |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2011-10-10 : 17:30:08
|
the values are all numbers yet the datatype is NVARCHAR?For why?Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-10-11 : 04:11:40
|
quote: Originally posted by Transact Charlie the values are all numbers yet the datatype is NVARCHAR?For why?Charlie
So that leading zeroes don't get lost maybe?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2011-10-11 : 20:15:11
|
but why would they be NVARCHAR?absolutely no requirement for extended charactersCharlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2011-10-12 : 02:35:23
|
Extension of webfred's method..where right(YourNumbersColumn,5) = '00000' and right(YourNumbersColumn,6) != '000000' PBUH |
 |
|
|