Solved

Declaring and Setting SQL Variables

Posted on 2014-03-27
2
200 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:
ScottPletcher earned 250 total points
Comment Utility
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
Comment Utility
>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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now