|
Home > Archive > Microsoft SQL Server forum > July 2005 > Using CASE or IF with INSERT
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using CASE or IF with INSERT
|
|
| CSDunn 2005-07-05, 8:23 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?
Consider the following code;
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,
If @FormType = 'SimplifiedApp Or (@FormType = 'AccidentApp' And @FormId
= 'AccidentAppRls0304'
) Then
@Gender
Else
'' )
The entry of a value for clnt_gender depends on the statements in the
If condition. If one condition is met, then the parameter value in
@Gender is used, otherwise, the entry is an empty string.
How would you recommend that I handle this kind of situation?
Thank you for your help!
CSDunn
| |
| David Portas 2005-07-05, 8:23 pm |
| 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
--
David Portas
SQL Server MVP
--
|
|
|
|
|