July 5, 2005 at 3:25 pm
Hello,
Within an INSERT statement where the VALUES are expressed, is it possible to evaluate one or more of the values with CASE or IF statements?
(entr_cd,
app_id,
clnt_id,
clnt_type,
clnt_frst_name,
clnt_mid_name,
clnt_lst_name,
clnt_gender)
(@EntrCode, @AppId, @ClientId, @FirstName, @MidName, @LastName,
@Gender
July 5, 2005 at 3:38 pm
I don't believe you can embed a CASE statement within an INSERT. I've never gotten it to work.
However, one possibility would be to create a UDF that takes the parameter and returns what you want inserted.
July 5, 2005 at 3:42 pm
How about Evaluate the @FormType and @FormId parameters, to set the value of Gender ID then insert.
You cannot do it inline in the Values Statement.
How about.
If @FormType = 'SimplifiedApp' Or
(@FormType = 'AccidentApp' And @FormId = 'AccidentAppRls0304')
Set @Gender = @Gender
else
set @Gender = ''
INSERT INTO snbat011_app_clnt
(entr_cd,
app_id,
clnt_id,
clnt_type,
clnt_frst_name,
clnt_mid_name,
clnt_lst_name,
clnt_gender)
VALUES
(@EntrCode, @AppId, @ClientId, @FirstName, @MidName, @LastName, @Gender)
July 5, 2005 at 3:54 pm
How about:
INSERT INTO snbat011_app_clnt
(entr_cd,
app_id,
clnt_id,
clnt_type,
clnt_frst_name,
clnt_mid_name,
clnt_lst_name,
clnt_gender)
SELECT
@EntrCode, @AppId, @ClientId, @FirstName, @MidName, @LastName
, CASE WHEN @FormType = 'SimplifiedApp' Or (@FormType = 'AccidentApp' And @FormId = 'AccidentAppRls0304') Then
@Gender ELSE '' END as Gender
* Noel
July 5, 2005 at 8:40 pm
As promised I have to agree with Noeld's solution .
July 6, 2005 at 8:33 am
Thanks for the help!
CSDunn
July 6, 2005 at 8:35 am
I knew it!
* Noel
July 6, 2005 at 8:45 am
A promess is a promess .
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply