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
 Update Query with variable in Where clause
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

StacyOW
Yak Posting Veteran

USA
86 Posts

Posted - 11/06/2012 :  12:58:47  Show Profile  Reply with Quote
I am trying to run the following query and it keeps telling me that zcomp is not a valid column name. zcomp is supposed to be the variable I am using to tell it which ComponentID I wish to update. It works fine if I put a value in place of zcomp, like 3089 - the ComponentID is and Integer, PK and Auto-increment. But it won't take the variable. Do I need to do something special to use the variable in place of the actual number?

Thanks,
Stacy

USE [MT]
GO
/****** Object:  StoredProcedure [dbo].[MaxDatePart]    Script Date: 11/06/2012 11:47:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[WOPartsUpdate]
(
@zamnt Integer,
@zcomp Integer
)
AS
BEGIN
SET NOCOUNT ON
UPDATE dbo.sparts
SET dbo.sparts.QtyonHand = dbo.sparts.QtyonHand + zamnt WHERE ComponentID=zcomp;
END

Edited by - StacyOW on 11/06/2012 13:02:50

TG
Flowing Fount of Yak Knowledge

USA
5924 Posts

Posted - 11/06/2012 :  13:39:34  Show Profile  Reply with Quote
you're missing the "@":

WHERE ComponentID=@zcomp;

EDIT:
and here too:
+ @zamnt

Be One with the Optimizer
TG

Edited by - TG on 11/06/2012 13:40:39
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 11/06/2012 :  13:40:28  Show Profile  Reply with Quote
it should be


USE [MT]
GO
/****** Object:  StoredProcedure [dbo].[MaxDatePart]    Script Date: 11/06/2012 11:47:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[WOPartsUpdate]
(
@zamnt Integer,
@zcomp Integer
)
AS
BEGIN
SET NOCOUNT ON
UPDATE dbo.sparts
SET dbo.sparts.QtyonHand = dbo.sparts.QtyonHand + zamnt WHERE ComponentID=@zcomp;
END


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.04 seconds. Powered By: Snitz Forums 2000