Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
694 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 27

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 27

Accepted Solution

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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

715 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