I am trying to write a stored procedure that I can execute with a given client name, and pass that client name as param to the create table statement inside the stored procedure. Here is the syntax I have:
IF EXISTS (SELECT name
WHERE name = 'Build_Invoice'
AND type = 'P')
DROP PROCEDURE Build_Invoice
CREATE PROCEDURE Build_Invoice (@Client Varchar(30) = " ")
Set @Client=@Client + '_Invoice'
CREATE TABLE dbo.@Client (
[Column1] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Column2] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
I am testing in by running this:
execute Build_Invoice 'Test' and expecting to get Test_Invoice as table name. I can create the sp just fine, but I cannot pass the param. Help!!!
Thanks in advance,