Jump to content

[TSQL] String concatenation


ironcurtain

Recommended Posts

While trying to run below query I got error:

Incorrect syntax near '+'.

declare @filepath varchar(50)set @filepath = 'e:\tsql\'create table #tab1 (name varchar(100))insert #tab1 exec master..xp_cmdshell 'dir /b "'+@filepath'"+"'*.txt'"'

I think there is issue with quatation marks but I couldn't find any solution. Please help.

Link to comment
Share on other sites

I founded solution for above:

declare @filepath varchar(50)set @filepath = 'e:\tsql\'declare @filetype varchar(5)set @filetype = 'txt'declare @commamd varchar(50)set @commamd = 'dir /b '+@filepath+@filetypecreate table #tab1 (name varchar(100))insert #tab1 exec master..xp_cmdshell @command

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...