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!

variable in SQL Alter statement

Status
Not open for further replies.

kewlcoder

Programmer
Dec 9, 2003
82
IN
Hi,

can i give a SQL command like this in VB

"alter table sal_Structure add @str1 int NULL"

here str1 is a string in VB so i have given it as @str1

please tell me if it is possible to use a string or a vriable for altering a given table

in both SQL and VB

thank you
Kewlcoder

in SQL i tried something like this kindly help me
I am new to SQL Programming

CREATE FUNCTION all_add()
returns bit
AS
DECLARE @itm VARCHAR(20)
DECLARE @succ bit
select @itm = all_code from all_Mas
where all_new = 1
ALTER TABLE sal_Structure ADD @itm VARCHAR(10)
GO

 
Replace the alter stmt with an the code below:
Code:
exec('ALTER TABLE sal_Structure ADD ' + @itm + ' VARCHAR(10)')

Regards,
AA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top