Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DECLARE A VARIABLE AND MOVE DATA TO FROM TABLE?

Status
Not open for further replies.

JohnKIT05

Technical User
Feb 18, 2005
19
US
I need to declare a new variable called @DATES to have a date field called INV_DATE from the table to be moved to the new variable field for comparison. I need to do this because while having the INV_DATE in the CASE statement in the SELECT statement, I will need to include the INV_DATE field in the GROUP BY statement. I do not want the INV_DATE field in the GROUP BY statement because it throws off the report.

I get an error "Invalid column name 'INV_DATE'.". The INV_DATE is a valid field in the table. Somehow I am confusing the server. Can this be done?. Example of the code in the beginning of the script is shown below.

USE NewMrgnDB
DECLARE @DATES smalldatetime
SET @DATES = INV_DATE
 
to set @dates to be a value from a table you need to include it in the select statement
i.e.
USE NewMrgnDB
DECLARE @DATES smalldatetime
SELECT @DATES = INV_DATE FROM MyTable

In your example it doesnt know what INV_Date is

"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top