It's not entirely clear what you mean but I'm fairly sure you want the
CASE (Transact-SQL)[
^] statement.
For example, using some test data generated by
Create Table Table1
(
id int identity(1,1),
someTextData AS 'Data' + Cast(id as varchar),
someDateData AS DATEADD(dd, id, CAST('2000-01-01' as Date))
)
go
insert into Table1 default values
go 100
You can adjust the results of the query thus
select
id, someTextData, someDateData,
CASE WHEN MONTH(someDateData) = 1 THEN 'January Sales'
ELSE someTextData
END as contrived
from Table1
On the other hand, if you mean that you have a variable declared and want to adjust it's value, you can still use the CASE statement
declare @AVariable INT = (select count(*) from Table1)
declare @AnotherVariable INT = CASE WHEN @AVariable > 50 then 1 else 0 end
select @AnotherVariable
If you are planning to do something a little more complex - e.g. multiple statements would depend on the condition then use the
IF...ELSE (Transact-SQL)[
^] statement
e.g.
IF @Avariable > 100
BEGIN
SET @AnotherVariable = 200
-- ... do some other stuff
END
ELSE
BEGIN
SET @AnotherVariable = 100
-- ... do some other stuff
END
select @AnotherVariable