If statement SQL

后端 未结 5 594
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 17:58

Hi i want to run an if statement but keep getting syntax errors near all my AS aliases, what am i doing wrong?

SELECT

IF @Origin = \'ALL\'


(SELECT COUNT(*         


        
5条回答
  •  青春惊慌失措
    2021-01-14 18:30

    I've just tried the following as a test and it works fine. You should be able to use this as a starting point for your example.

    DECLARE @Origin NVARCHAR(200)
    SET @Origin = 'ALL'
    IF @Origin = 'ALL'
        BEGIN
        (SELECT ('Test') AS HI)
        END
    ELSE
        BEGIN
            (SELECT ('Test2') AS HI)
        END
    

提交回复
热议问题