Friday, February 24, 2012

contains keyword for integer field type

I have a field ID of type integer, I want to put two numbers in that field: 3 and 7, so what I do is just store the number 37.

Now, is there a command in SQL server which checks if the ID field contains a number I look for, say 7.
Something like a CONTAINS keyword...

If there is, could someone please tell me what it is AND tell me a bit more about it :memory usage, (dis)advantages etc.

try something like this:

select

ID/10 firstDigit,
ID- ID/10*10 secondDigit
from(select 37 [ID])aa

It will work as long as Your ID is Int type if it is not int do this

select ID/10 firstDigit,
ID- ID/10*10 secondDigit
from(select cast(37.00 as int) [ID])aa

You can also use substring
selectsubstring(ID,1,1) first,substring(ID,2,1) second
from(selectcast(37asvarchar(20)) [ID])aa

Good luck

No comments:

Post a Comment