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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 invalid coloum name error

Author  Topic 

nto
Starting Member

12 Posts

Posted - 2009-07-16 : 03:30:19
Hi guys, i need some help in here.

CREATE PROCEDURE proc_maintenance_getMostRecent
@mobileID int,
@make varchar (100) OUTPUT,
@model varchar (100) OUTPUT,
@VIN varchar (100) OUTPUT,
@Registration varchar (100) OUTPUT

AS
BEGIN
SET NOCOUNT ON

IF EXISTS (
SELECT TOP 1 make,model,VIN,Registration
FROM maintenance
WHERE
mobileid = @mobileID
ORDER BY
InstallationDT DESC)

SET @make = make
SET @model = model
SET @VIN = VIN
SET @Registration = Registration
END

For some reason it give me an error "invalid coloum name for 'make', 'model','VIN' and 'Registration'
i checked all field are exist in maintenance table.
mayb it put wrong syntax, basicly what i want to do is,
i want to output the most recent make, model, vin and registration from maintenance table.

any help appreciated.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-16 : 03:56:41
You cannot use make,model,VIN,Registration without a select.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

nto
Starting Member

12 Posts

Posted - 2009-07-16 : 04:06:48
so i have to do something liek this?
SET @make = (SELECT make from maintenance where mobileID= @mobileID ORDER BY installationDT DESC)
etc etc
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-16 : 04:16:06
select
@make = make,
@model = model,
@VIN = VIN,
@Registration = Registration
from table
where blabla



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-16 : 04:17:21
And make sure that your select returns only one row!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-16 : 14:06:29
for getting most recent values just use this modified webfred's soln

select TOP 1
@make = make,
@model = model,
@VIN = VIN,
@Registration = Registration
from maintenance where mobileID= @mobileID
ORDER BY installationDT DESC
Go to Top of Page

nto
Starting Member

12 Posts

Posted - 2009-07-16 : 21:41:10
yup it works now thank you so much,
however i managed to return as an object, so i can use couple field instead only 1

Thanks for your help guys
Go to Top of Page
   

- Advertisement -