473,467 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to write an if statement in stored procedure

34 New Member
hi .
Actually i have a statement If @Stat in (20,30) i want to
to modify it as
if @Stat = 20 set Status="Rejected"
if @Stat = 30 set Status=" Accepted"

Can you please help me out here .
i have tried but i am getting an error...

Server: Msg 170, Level 15, State 1, Line 4
Line 4: Incorrect syntax near '='.
Server: Msg 170, Level 15, State 1, Line 5
Line 5: Incorrect syntax near '='.

thanks in advance
Sep 28 '07 #1
3 1368
ck9663
2,878 Recognized Expert Specialist
hi .
Actually i have a statement If @Stat in (20,30) i want to
to modify it as
if @Stat = 20 set Status="Rejected"
if @Stat = 30 set Status=" Accepted"

Can you please help me out here .
i have tried but i am getting an error...

Server: Msg 170, Level 15, State 1, Line 4
Line 4: Incorrect syntax near '='.
Server: Msg 170, Level 15, State 1, Line 5
Line 5: Incorrect syntax near '='.

thanks in advance
are you trying to store the string "Rejected" to a variable? if yes, try:

Expand|Select|Wrap|Line Numbers
  1. if  @Stat  = 20   set @Status='Rejected'
  2. if  @Stat = 30    set @Status='Accepted'
  3.  
if you're trying to update a table and Status is a column, you have to do a

Expand|Select|Wrap|Line Numbers
  1. if  @Stat  = 20   
  2. update mytable
  3. set Status='Rejected'
  4.  
Sep 28 '07 #2
sanika1507
34 New Member
are you trying to store the string "Rejected" to a variable? if yes, try:

Expand|Select|Wrap|Line Numbers
  1. if  @Stat  = 20   set @Status='Rejected'
  2. if  @Stat = 30    set @Status='Accepted'
  3.  
if you're trying to update a table and Status is a column, you have to do a

Expand|Select|Wrap|Line Numbers
  1. if  @Stat  = 20   
  2. update mytable
  3. set Status='Rejected'
  4.  

thanks for your help . but the status is not a variable .its a column name in a table.........
Sep 28 '07 #3
ck9663
2,878 Recognized Expert Specialist
thanks for your help . but the status is not a variable .its a column name in a table.........
if you're trying to replace the value of Status based on the value of the variable @stat, then the second one should do it. if stat and status are on the same table, then you have to do something like...

Expand|Select|Wrap|Line Numbers
  1. update myTable
  2. set Status = case when stat = '20' then 'Rejected' when stat = '30' then Accepted end
  3.  
Sep 28 '07 #4

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

Similar topics

0
by: Jeff Mason | last post by:
Consider the following (questionable, to be sure, but syntactally legal) stored procedure (using the Northwind database): Create Procedure Test As Return (Select Count(*) From Orders) Select *...
4
by: Raquel | last post by:
This is regarding SQL stored procedures. The guide says this about handler declaration in SQL procedures: "handler declaration can specify a SQL-procedure-statement. SQL-procedure-statement is a...
2
by: Rhino | last post by:
Is there some kind of requirement that a DECLARE CONTINUE HANDLER statement follow the DECLARE CURSOR statement in an SQL stored procedure? I am running DB2 V8.2.1 on Windows XP and am writing my...
6
by: Terentius Neo | last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a select statement? I mean something like this: Select c.number, call procedure( c.number ) as list from table c With best...
2
by: Rajat Katyal | last post by:
Hi: I prepare the statement for execution as follows: PREPARE query(text) as SELECT count(*) FROM transform_customer_billing where inv_no = $1; The problem is Iam not able to execute this...
6
by: Not4u | last post by:
Hello Config : SQL 2000 on WIN 2000 (IIS 5.0) In my ASP page for some queries i have this error : Microsoft OLE DB Provider for SQL Server error '80040e31' Timeout expired
2
by: Beowulf | last post by:
If I run this statement in Query Analyzer, it properly returns 1 for my testing table. But if I put the statement into a stored procedure, the stored procedure returns NULL. What am I doing...
2
by: eflatunn | last post by:
Hi all, I paid 3 hours for it but couldn't get succeed. I'm writing a stored procedure to get a data entry in a table. The problem is that I can't simply use commands "SELECT" or "CASE" directy....
6
by: Szymon Dembek | last post by:
Hello to everyone, I'm currently doing some UDF and stored procedure development in DB2 v.9. I have a problem with the following construct: SET (var_a, var_b) = (select a, b from table1...
2
by: kxyz | last post by:
Hello everyone, I need help with a stored procedure or two. My stored procedures are supposed to check if a certain record exists. If it does exist, then I select everything from that row, as...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.