473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Assigning values to multiple variables (via subqueries) for use in an update

Hi, figured out where I was going wrong in my post just prior, but is
there ANY way I can assign several variables to then use them in an
Update statement, for example (this does not work):

ALTER PROCEDURE dbo.UpdateXmlWF
(
@varWO varchar(50)
)
AS
DECLARE @varCust VARCHAR(50)
SELECT @varCust = (SELECT Customer FROM tblWorkOrders
WHERE WorkOrder=@varWO)

DECLARE @varAssy VARCHAR(50)
SELECT @varAssy=(SELECT Assy FROM tblWorkOrders
WHERE WorkOrder=@varWO)

UPDATE statement here using declared variables...

I can set one @variable but not multiple. Any clues? kinda new to
this.

Thanks,
Kathy
Jul 20 '05 #1
2 6631
Kathy,

See my response to your previous post.

I think you want to try this instead:

DECLARE @varCust varchar(50), varAssy varchar(50)
SELECT @varCust = Customer,
@varAssy = Assy
FROM tblWorkOrders
WHERE WorkOrder = @varWO

UPDATE table
SET field = @varCust,
field2 = @varAssy
where somefield = somevalue

In fact, you could condense this to the following:

UPDATE table
SET field = tblWorkOrders.Customer,
field2 = tblWorkOrders.Assy
FROM tblWorkOrders
JOIN table ON tblWorkOrders.PK = table.FK
WHERE tblWorkOrders.WorkOrder = @varWO
AND otherconditions...

Hope this helps.

--
-Chuck Urwiler, MCSD, MCDBA
http://www.eps-software.com
Jul 20 '05 #2
Kathy,

You don't need two separate SELECT statements to assign values to your
variables. You can do it like this:

DECLARE @varCust VARCHAR(50),
@varAssy VARCHAR(50)

SELECT @varCust = Customer,
@varAssy = Assy
FROM tblWorkOrders
WHERE WorkOrder = @varWO

But I don't understand your problem with inserting. You can modify as many
columns as you want in UPDATE statement. What's your problem here?
By the way, if these variables have been declared just to use in your UPDATE
statement, then you don't really need them. You can join tblWorkOrders table
with whatever table you want update and fetch values from tblWorkOrders
directly into your destination table.

Shervin

"KathyB" <Ka**********@attbi.com> wrote in message
news:75*************************@posting.google.co m...
Hi, figured out where I was going wrong in my post just prior, but is
there ANY way I can assign several variables to then use them in an
Update statement, for example (this does not work):

ALTER PROCEDURE dbo.UpdateXmlWF
(
@varWO varchar(50)
)
AS
DECLARE @varCust VARCHAR(50)
SELECT @varCust = (SELECT Customer FROM tblWorkOrders
WHERE WorkOrder=@varWO)

DECLARE @varAssy VARCHAR(50)
SELECT @varAssy=(SELECT Assy FROM tblWorkOrders
WHERE WorkOrder=@varWO)

UPDATE statement here using declared variables...

I can set one @variable but not multiple. Any clues? kinda new to
this.

Thanks,
Kathy

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ben | last post by:
Hi all, This may sound easy but I'm having trouble assigning values to array element. My problem is as follows: m = for o in m: # Here first o is 'Peter'.. I want to do something like this:...
10
by: Johnny Lin | last post by:
Hi! Is there a way to automate the unbinding of multiple variables? Say I have a list of the names of all variables in the current scope via dir(). Is there a command using del or something...
8
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to...
14
by: Eric Bantock | last post by:
Very basic question I'm afraid. Once an array has been declared, is there a less tedious way of assigning values to its members than the following: myarray=8; myarray=3; myarray=4; myarray=0;...
3
by: Kiran A K | last post by:
In C#, i have seen values being assigned to strings in 2 ways. 1) string name = "Bill Gates"; 2) string name = ("Bill Gates"); what is the difference betn. the 2 methods if any? the second...
1
by: syntego | last post by:
I am using DB2 V8 fixpack 10 and have the following issue: >From a User Defined Function, I can assign multiple variables in a single statement as follows: -- Get the first update transaction...
1
by: Xqzrt | last post by:
Is there a way to assign a variable like "A+" to a value, like "5.5"?
7
by: r.z. | last post by:
This is from Visual Studio docs. But is this standard behaviour? I mean, is it ok in every environment: class A { B* my_pointer; A(); ~A(); }
7
by: hash4sp | last post by:
Hi, Can anyone please advise me on the following. Here I have a bunch of variables in an array. And then those arrays in another array. I want to assign values to those variables in arrays. Is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.