Can you please tell me what is wrong in this query? I am trying to write a SQL query to create a table dynamically
DECLARE @SQLString NVARCHAR(MAX)
SET @SQLString =+ 'Create Table' + GETDATE() + '_' + 'Table' + '' + '(' + 'Column1' + ' ' + 'Nvarchar(50)' + 'Null' + ')' +
Exec @SQLString ;
Best Answer
There are multiple issues with your string
@SQLString
:+
at the beginning and at the end[
and]
.exec sp_executesql @SQLString
So your script might work with this:
I'd recommend reading up on the CREATE TABLE statement and on the String Functions. Then carry on to the Data Type Conversion documentation and have a glimpse at the sp_executesql syntax.
Good Luck.