Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Parameters With SSMS

Author  Topic 

sirmilt
Starting Member

49 Posts

Posted - 2010-11-02 : 18:03:30
I am trying to create a query using the SSMS The code looks like this:

SELECT tblBooks.ID, tblBooks.Collection, tblBooks.Title, tblBooks.Authors, tblBooks.Series, tblBooks.Issued, tblBooks.Price, tblBooks.ISBN, tblBooks.Category,
tblBooks.Condition, tblBooks.Type, tblBooks.Signed, tblBooks.BookLoanStatus, tblBooks.Comments, tblOnLoan.LoanID, tblOnLoan.LoanStatus,
tblOnLoan.CollectionID, tblOnLoan.Title AS Expr1, tblOnLoan.LoanDate
FROM tblBooks INNER JOIN
tblOnLoan ON tblBooks.ID = tblOnLoan.CollectionID
WHERE (tblBooks.ID = @ID)
When I try to execute this query in the SSMS Query Builder I get this error:

Msg 137, Level 15, State 2, Line 6
Must declare the scalar variable "@ID".


I can't find any source to point me in the right direction. Can anyone help?

Milt

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-02 : 18:05:47
SELECT tblBooks.ID, tblBooks.Collection, tblBooks.Title, tblBooks.Authors, tblBooks.Series, tblBooks.Issued, tblBooks.Price, tblBooks.ISBN, tblBooks.Category,
tblBooks.Condition, tblBooks.Type, tblBooks.Signed, tblBooks.BookLoanStatus, tblBooks.Comments, tblOnLoan.LoanID, tblOnLoan.LoanStatus,
tblOnLoan.CollectionID, tblOnLoan.Title AS Expr1, tblOnLoan.LoanDate
FROM tblBooks INNER JOIN
tblOnLoan ON tblBooks.ID = tblOnLoan.CollectionID
WHERE tblBooks.ID = SomeIntValue

OR:

DECLARE @ID int

SET @ID = SomeIntValue

SELECT tblBooks.ID, tblBooks.Collection, tblBooks.Title, tblBooks.Authors, tblBooks.Series, tblBooks.Issued, tblBooks.Price, tblBooks.ISBN, tblBooks.Category,
tblBooks.Condition, tblBooks.Type, tblBooks.Signed, tblBooks.BookLoanStatus, tblBooks.Comments, tblOnLoan.LoanID, tblOnLoan.LoanStatus,
tblOnLoan.CollectionID, tblOnLoan.Title AS Expr1, tblOnLoan.LoanDate
FROM tblBooks INNER JOIN
tblOnLoan ON tblBooks.ID = tblOnLoan.CollectionID
WHERE tblBooks.ID = @ID

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-11-02 : 20:15:13
...when you say.."Create a Query using SSMS..."

by that you mean????



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -