Solved

Declaring and Setting SQL Variables

Posted on 2014-03-27
2
213 Views
Last Modified: 2014-03-27
I am trying to write a SQL statement that uses a very simple variable.
I keep getting an error that says:
"The multipart identifier could not de bound"

Here is an example of my statement:

USE TSQL2012
GO
DECLARE @Total Int;
SET @Total = (Sales.OrderDetail.unitprice * Sales.OrderDetail.qty)
SELECT @Total AS 'Total Price'
FROM Sales.OrderDetail

What am I missing
0
Comment
Question by:mnoisette
2 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 39959177
DECLARE @Total Int;

SELECT @Total = SUM(od.unitprice * od.qty)
FROM Sales.OrderDetail od

SELECT @Total AS 'Total Price'
0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 39959179
>SET @Total = (Sales.OrderDetail.unitprice * Sales.OrderDetail.qty)
Is your intent to run a select query, and assign the single value to @total?

If so, it needs to be something like this...
SELECT @Total = unitprice * qty
FROM Sales.OrderDetail

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

685 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