Friday, February 22, 2008

Declare variable in MS SQL

To use the same variable multiple times do this:

DECLARE @Value Int
SET @Value = 134

select * from table where table_id = (@Value)

Thanks to: http://www.java2s.com/Code/SQLServer/Transact-SQL/Declareavarcharvariable.htm

This is very helpful when you want to use the same value multiple times on a query or something like that.

No comments: