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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 sp help

Author  Topic 

ann
Posting Yak Master

220 Posts

Posted - 2010-05-01 : 19:41:40
does anyone know how I can search based on the last 4 digits of an int column?

@Num int

select * from table
where intcolumnlast4digits = @num

thanks

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-05-01 : 23:34:04
[code]SELECT * FROM table
WHERE RIGHT(CAST(intcolumnlast4digit AS VARCHAR(18)), 4) = @num;[/code]
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-02 : 00:25:50
[code]
select *
from table
where intcolumnlast4digits % 10000 = @num
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-07 : 10:06:03
If you want to make use of index

select *
from table
where intcol like '%'+cast(@num as varchar(10))

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -