Solved

A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.

Posted on 2009-04-06
3
672 Views
Last Modified: 2012-05-06
Hi

Why the following SP make the error:

A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.


@id int
AS
BEGIN
Declare @clientid int
Declare @currencyid int
select @clientid = clientid, @currencyid = currencyid, amount from transactions where id = @id

Open in new window

0
Comment
Question by:techques
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Expert Comment

by:Chris Luttrell
ID: 24083950
because "@clientid = clientid, @currencyid = currencyid" in the select in assinging values to those variables and "amount" is trying to retrieve the amount value.  You can not do both in one statement.
0
 

Author Comment

by:techques
ID: 24083989
Does the following work?
Declare @clientid int
Declare @currencyid int
Declare @amount decimal (18,2)
select @clientid = clientid, @currencyid = currencyid, @amount = amount from transactions where id = @id

Open in new window

0
 
LVL 26

Accepted Solution

by:
Chris Luttrell earned 50 total points
ID: 24084076
Yes it should run and give you the values in your 3 variables.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PERFORMANCE OF SQL QUERY 13 77
SQl Agent job fails--SSIS package looses password 6 58
Pivot Query Problem 9 49
Order by but want it in specific order 2 35
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question