General discussion

Locked

Update Qurey For MS SQL

By berkimdgkr ·
I need to make conditional update qurey. It has to compare the one of field in the record which will be updated. Is there anyway to make condition?

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

use PL/SQL

by lehttn In reply to Update Qurey For MS SQL

You can use PL/SQL to make a script like this:
declare @field1 numeric;
select @field1 = Field1 from Table1 where ...;
if @field1 == @condition1
update Table1 set ... where ...;
--
(@condition1 is the value you want to compare Field1 with)Good luck.

Collapse -

No - use T-SQL

by Bucky Kaufman (MCSD) In reply to use PL/SQL

You can't use PL/SQL on SQL Server (MS SQL). You have to use T-SQL (Transact SQL).

To solve this problem, the user should use a "CASE" expression.

You COULD use a version of the PL/SQL method prior to this post. However, it calls for the user to create a paramaterized query, and then to call that query with the parameters set. Issuing two seperate SQL statements as one is not something you can do with T-SQL. So you'd have to create the query as a Stored Procedure at design time, instead of composing it as a non-compiled SQL statement ad runtime.

Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums