Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using variables

Status
Not open for further replies.

TomBarrand

Programmer
Joined
Aug 9, 2000
Messages
162
Location
GB
I am using a product that is passing a value into a stored procedure in SQL Server. I then want to pass the value held within the stored procedure into a WHERE statement in a view that I am using.

Is this possible? If so, how do I do it?

Thanks
 

Is this what you need to do?

Create procedure MyTestProc @param varchar(40) AS

Select * From vMyTestData
Where Col1=@param

If not, please provide more detail. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Is it possible to create a dynamic view, e.g.

CREATE PROCEDURE sp_FOB_No
@FOBNo INT,
@FolderID VARCHAR(31) AS

CREATE VIEW @FOLDERNAME

SELECT FOB_No, Size_No, Ratio, Size_Quantity
FROM dbo.FOB_Size
WHERE (FOB_No = 213)

return
GO
 

You can. I question why you want to do this but it is possible.

CREATE PROCEDURE sp_FOB_No
@FOBNo INT,
@FolderName VARCHAR(31) AS

DECLARE @sql nvarchar(200)

SELECT @sql='CREATE VIEW ' + @FOLDERNAME + ' AS ' +
'SELECT FOB_No, Size_No, Ratio, Size_Quantity' +
'FROM dbo.FOB_Size' +
'WHERE FOB_No = ' + str(@FOBNo)

EXEC(@sql)

return
GO Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top