I have this structure inside a function:
INSERT INTO @TheTable
SELECT DISTINCT
@Number AS Number,
@Name AS Name
FROM MYTABLE
WHERE id = @id
I need to add to this structure the result of executing another function and I need your help to do so.
Below the @Name AS Name, line I should add something like this
IF (dbo.anotherFunction(@id)==1)
@NewVisitor AS NewVisitor
ELSE
@NewVisitor AS NoNewVisitor
How can I translate this into TSQL??
Thanks a million!
Guessing this is what you want...
INSERT INTO @TheTable
SELECT DISTINCT
@Number AS Number,
@Name AS Name,
case when (dbo.anotherFunction(@id)=1) then @NewVisitor else null end as NewVisitor,
case when (dbo.anotherFunction(@id)<>1) then @NewVisitor else null end AS NoNewVisitor
FROM MYTABLE
WHERE id = @id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With