SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored procedure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Fulkan
Starting Member

2 Posts

Posted - 04/20/2013 :  17:40:58  Show Profile  Reply with Quote
i got a problem with a easy stored procedure that gives me the error: Incorrect syntax near keyword 'select'. Must declare the scalar variable "@llnnr".

------------------------------
ALTER procedure ziekeleerling

@voornaam varchar(50),
@achternaam varchar(50)

as
begin
declare @llnnr as numeric = select llnnr from Leerlingen where @voornaam = voornaam


insert into Ziektes
(llnnr,voornaam,achternaam,datum)
values(@llnnr,@voornaam,@achternaam,getdate())
end
------------------------------

i have a table with automatic raise on the primary key (nummeric) for evey new entry. it has 3 fields "voornaam", "achternaam" and "llnnr". all i want in the declare is for the @llnnr to get the value of llnnr on the place where the @voornaam is "voornaam" in my table. i can't figure out the error

MuMu88
Aged Yak Warrior

547 Posts

Posted - 04/20/2013 :  20:10:59  Show Profile  Reply with Quote
Use parenthesis around your select statement as shown in red below:



declare @llnnr as numeric = (select llnnr from Leerlingen where @voornaam = voornaam)

Go to Top of Page

Fulkan
Starting Member

2 Posts

Posted - 04/21/2013 :  09:55:37  Show Profile  Reply with Quote
... i feel like such a clown now, that i could have missed that, thank you
Go to Top of Page

MuMu88
Aged Yak Warrior

547 Posts

Posted - 04/21/2013 :  10:29:37  Show Profile  Reply with Quote
No worries, it happens to the best of us
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 04/22/2013 :  01:39:59  Show Profile  Reply with Quote
quote:
Originally posted by Fulkan

... i feel like such a clown now, that i could have missed that, thank you


hope you'll have only one record per value of voornaam otherwise the select will fail

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000