I not sure why I am getting error with following dynamic sql :
IF @unique_identifier = 1 AND (EXISTS(SELECT * FROM table1
WHERE field_value = @field_value
AND field_id = @field_id)
OR EXISTS (SELECT * FROM table2 WHERE field_value = @field_value
AND field_id = @field_id))
SELECT @operation_result_code = 99,
@operation_message = message_desc
FROM cdosys_message
where message_code='USER_DEFINED_FIELD_UNIQUE_IDENTIFIER'
SET @select= 'ELSE IF ' + ''''+CONVERT(VARCHAR,@as_of_date,110)+''''+' IS NULL AND NOT EXISTS(SELECT TOP 1 * FROM ' + @table + ' WHERE issue_id =' +convert(varchar(10),@field_id)+')'
Exec (@select)
Error:
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'ELSE'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ')'.
any idea?
IF @unique_identifier = 1 AND (EXISTS(SELECT * FROM table1
WHERE field_value = @field_value
AND field_id = @field_id)
OR EXISTS (SELECT * FROM table2 WHERE field_value = @field_value
AND field_id = @field_id))
SELECT @operation_result_code = 99,
@operation_message = message_desc
FROM cdosys_message
where message_code='USER_DEFINED_FIELD_UNIQUE_IDENTIFIER'
SET @select= 'ELSE IF ' + ''''+CONVERT(VARCHAR,@as_of_date,110)+''''+' IS NULL AND NOT EXISTS(SELECT TOP 1 * FROM ' + @table + ' WHERE issue_id =' +convert(varchar(10),@field_id)+')'
Exec (@select)
Error:
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'ELSE'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ')'.
any idea?