Solved

Declaring and Setting SQL Variables

Posted on 2014-03-27
2
207 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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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 insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

810 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