473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

sql stored procedure parameter problem

3
Hello,

I have used stored procedure with parameters.Now I want to use the parameter in the select statement.Following is my code in the procedure.

////////////////////////////////////
CREATE PROCEDURE locationproduct
@tlocation varchar(10),
@tproduct varchar(10)
@TableName varchar(10)
AS

declare @firstquarter int;

SET @firstquarter =
( SELECT SUM(DemandCol) AS firstquarter FROM DemandTable
WHERE location = @tlocation AND product= @tproduct )

insert into abc values (@tlocation,@first);


In the above instead of DemandTable I want to use TableName .
How do I do That?

Thanks,
Prithaa
Dec 20 '07 #1
2 1316
deepuv04
227 Expert 100+
Hello,

I have used stored procedure with parameters.Now I want to use the parameter in the select statement.Following is my code in the procedure.

////////////////////////////////////
CREATE PROCEDURE locationproduct
@tlocation varchar(10),
@tproduct varchar(10)
@TableName varchar(10)
AS

declare @firstquarter int;

SET @firstquarter =
( SELECT SUM(DemandCol) AS firstquarter FROM DemandTable
WHERE location = @tlocation AND product= @tproduct )

insert into abc values (@tlocation,@first);


In the above instead of DemandTable I want to use TableName .
How do I do That?

Thanks,
Prithaa

First build the select statement as a string and then execute the string


CREATE PROCEDURE locationproduct
@tlocation varchar(10),
@tproduct varchar(10)
@TableName varchar(10)
AS

declare @firstquarter int;

declare @str varchar(1000)

set @str = 'SELECT SUM(DemandCol) AS firstquarter FROM '+@TableName+' WHERE location = ' +
convert(varchar(10),@tlocation) + ' AND ' + convert(varchar(10),@tproduct)

SET @firstquarter = Exec (@str)



insert into abc values (@tlocation,@first);
Dec 20 '07 #2
PRITHA
3
Many many Thanks deep.
Dec 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
3
by: Bilbo | last post by:
I have a a headscratcher here: I have a form that when submitted should do 2 things when a user enters data and then clicks the Add button. Here goes: 1. Call a stored procedure called...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
1
by: jkeel | last post by:
If I try to Update a record with the following code using a stored procedure I get an error: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
3
by: .Net Sports | last post by:
I need to call an stored procedure from an asp script, I don't need to do an Output parameter, only input parameters on 3 vars, but I get a "BOF EOF not true or record has been deleted" error when...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.