471,090 Members | 1,321 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,090 software developers and data experts.

Using CASE or IF with INSERT

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

Jul 23 '05 #1
1 1868
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
--

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Lauren Quantrell | last post: by
reply views Thread by Marko Poutiainen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.