471,071 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

If statments in MSSQL

17
Iím am trying to create a StoredProc that will, if a value is below a limit it will insert one value or if the value is above a limit then it will insert another value. Sort of like this in C programming:

Expand|Select|Wrap|Line Numbers
  1.             if (ValueOriginal >= 3)
  2.             {
  3.                 if (ValueOriginal <= 10)
  4.                     ValueToInsert = ValueOriginal;
  5.                 else
  6.                     ValueToInsert = 0;
  7.             }
  8.             else
  9.                 ValueToInsert = 0;
Hope Someone can help me

NormanTheDane
Mar 2 '07 #1
4 33912
prileep
20
Iím am trying to create a StoredProc that will, if a value is below a limit it will insert one value or if the value is above a limit then it will insert another value. Sort of like this in C programming:

Expand|Select|Wrap|Line Numbers
  1.             if (ValueOriginal >= 3)
  2.             {
  3.                 if (ValueOriginal <= 10)
  4.                     ValueToInsert = ValueOriginal;
  5.                 else
  6.                     ValueToInsert = 0;
  7.             }
  8.             else
  9.                 ValueToInsert = 0;
Hope Someone can help me

NormanTheDane
If u just want to know how to use IF state ment in SQL Server,

Format one:
IF <condition> <then code to be executed when condition true>
Format two:
IF <condition>
BEGIN
<then code to be executed when condition true>
END
ELSE
BEGIN
< else code to be executed when condition is false>
END
Mar 2 '07 #2
almaz
168 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. insert <<YourTableName>> (<<ListOfFields>>) values 
  2. (case 
  3.     when @ValueOriginal >= 3 and @ValueOriginal <= 10 then @ValueOriginal 
  4.     else 0 
  5. end, <<OtherFields>>)
Mar 2 '07 #3
hariharanmca
1,977 1GB
Iím am trying to create a StoredProc that will, if a value is below a limit it will insert one value or if the value is above a limit then it will insert another value. Sort of like this in C programming:

Expand|Select|Wrap|Line Numbers
  1.             if (ValueOriginal >= 3)
  2.             {
  3.                 if (ValueOriginal <= 10)
  4.                     ValueToInsert = ValueOriginal;
  5.                 else
  6.                     ValueToInsert = 0;
  7.             }
  8.             else
  9.                 ValueToInsert = 0;
Hope Someone can help me

NormanTheDane


Expand|Select|Wrap|Line Numbers
  1.   if  ValueOriginal >= 3
  2.             Begin
  3.                 if  ValueOriginal <= 10 
  4.                     ValueToInsert = ValueOriginal
  5.                 else
  6.                     ValueToInsert = 0
  7.             end
  8.             else
  9.                 ValueToInsert = 0

Try This
Mar 2 '07 #4
Normann
17
Thanks for all your help, I have it working now.
Mar 2 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by badz | last post: by
7 posts views Thread by mj | last post: by
14 posts views Thread by Kukurydz | last post: by
11 posts views Thread by ralphie | last post: by
8 posts views Thread by php-taz | last post: by
14 posts views Thread by guswebb | 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.