|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm sure this is really quite simple, but no matter how hard I try I can't get it to work.
I have several stored procedures that proform the same function but on different tables. I call the SP_ from ASP code. They all work fine, but it would make things easier if I could use the same SP_ and pass the relevant table name into the it. The problem example is: FROM tblQWIfiles WHERE Datafile = @Datafile, the same applies to the INSERT INTO line. I want tblQWIfiles to be a variable, but I can't seem to declare it correctly and get it past the syntax checker. Any help is much apprieciated and sorry if this really is simple. Here is a copy of my working code: <code> CREATE PROCEDURE [insert_tblQWIfiles2] ( @Folder [varchar](50), @Datafile [varchar](100), @Issue [char](10), @Revision [char](10), @Owner [varchar](50), @Extension [char](3), @User [varchar](100) ) AS SET NOCOUNT ON DECLARE @cnt int BEGIN SELECT @cnt = count(*) FROM tblQWIfiles WHERE Datafile = @Datafile IF @cnt = 0 BEGIN INSERT INTO tblQWIfiles ( [Folder], [Datafile], [Issue], [Revision], [Owner], [Extension], [LastUpdated], [LastUpdateUser] ) VALUES ( @Folder, @Datafile, @Issue, @Revision, @Owner, @Extension, Getdate(), @User ) SELECT 'OK' AS 'Status' RETURN(0) END ELSE BEGIN SELECT 'ERR' AS 'Status' RETURN(1) END END GO <code> |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > How can I use a dynamic Table name in a stored procedure |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|