My procedure
ALTER PROCEDURE [dbo].[spMyProc]
@uniqueid uniqueidentifier,
@y int
DECLARE @ID uniqueidentifier
SELECT TOP 1 @ID = uniqueid FROM tbl_x WHERE y= @y
INSERT INTO tbl_x
(
otherfield
,uniqueid
)
VALUES
(
@otherfields
,if @ID == null then @uniqueid else @ID -- this is what i want to happen how i do not know
)
Now i can do this using if else block like this but i do not want to do it. I want some nice way of coding this
this is what i do not want to do
if(@id IS NULL)
BEGIN
INSERT INTO tbl_x
(
otherfield
,uniqueid
)
VALUES
(
@otherfields
,@uniqueid
)
END
ELSE
BEGIN
INSERT INTO tbl_x
(
otherfield
,uniqueid
)
VALUES
(
@otherfields
,@id
)
END
is there any suggestion