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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a variable in a query 1

Status
Not open for further replies.
Sep 19, 2002
34
0
0
US
I am trying to use a field in a table to provide the variable for this query. I get an error: "The column prefix 'tblvdte' does not match with a table name or alias name used in the query."
I have searched the error and found little to aid me.
Here is the query:

declare @rundte as int
set @rundte = tblvdte.rundte

SELECT cast(SUM(RDSIZE * RDNPPB)+.05 as int) AS SCHED,
cast(SUM(RDSIZE * RDNEPB)+.05 as int) AS Prod
FROM RMODELT1 join tblvdte on
rmodelt1.rdpmnm <> tblvdte.rundte

WHERE (RDRSDT = @rundte) AND (RDPMNM < '01999')

Can someone give some direction as to how to accomplish this.
 
You can't SET a variable to Table field, you could only SELECT it:
Code:
declare @rundte as int
SELECT @rundte = tblvdte.rundte FROM tblvdte WHERE ...

SELECT     cast(SUM(RDSIZE * RDNPPB)+.05 as int) AS SCHED,
 cast(SUM(RDSIZE * RDNEPB)+.05 as int) AS Prod
FROM RMODELT1
join tblvdte  on rmodelt1.rdpmnm <> tblvdte.rundte
WHERE     (RDRSDT = @rundte) AND (RDPMNM < '01999')

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Borislav
Thanks very much for the response
That works!

I am very new to this stuff and have been getting little bits and pieces from this forum to get to where I am.
If I can impose once again, what would be the best resource to track down these type of questions in syntax etc.

Thanks again for your assistance.
 
Here :)
Ask questions, read FAQ. BOL is also a great help.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Borislav, You're right. Here is great. Also the BOL was something I was unaware of. I was searching through the help file and finding nothing. (I now know it was help only for the MMC). What a great journey this will be.

I have implemented things today that are very clear thanks to your assistance. When I figure out how to give you a Star... you will get one.

Thanks again.
 
[lol]
Just after my signature there is a signe with somethinh like "Thank bborissov for ..."

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
While in Query Analyzer, you can press F1 to get help on the query analyzer (not very helpful). But, you can press [!]SHIFT-F1[/!] to get to books on line where the sql syntax is explained.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks for jumping in to offer assistance. You guys are great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top