Link to home
Start Free TrialLog in
Avatar of BruceThiessen
BruceThiessenFlag for United States of America

asked on

T-SQL INSERT INTO with both a STRING and an EXEC?

Can't quite seem to get the syntax right here:

INSERT INTO LinkedFiles (LinkType,FPathName) Values ('MasterID',EXEC master..xp_cmdshell 'dir "c:\custom\vehicles" /b /s')
Avatar of OCDan
OCDan
Flag of United Kingdom of Great Britain and Northern Ireland image

Try This:
INSERT INTO LinkedFiles (LinkType,FPathName) Values ('MasterID','EXEC master..xp_cmdshell 'dir "c:\custom\vehicles" /b /s'')

Open in new window


I think it was just missing a few ' s
Avatar of BruceThiessen

ASKER

Now tells me: incorrect syntax by 'dir'
Avatar of j4v4soft
j4v4soft

dir "c:\custom\vehicles" /b /s
That's what I have... it's the ' before the dir that is giving me problems...
When I ran the EXEC separately, it worked fine... now that I enclose the whole command with single quotes, that is where I am having difficulty...
Do I need to use a temp table for the EXEC statement, then combine with my other value in a second INSERT?
EXECUTE cannot be used as a source when inserting into a table variable...
Avatar of Anthony Perkins
>>Do I need to use a temp table for the EXEC statement, then combine with my other value in a second INSERT? <<
That is correct.  Let me know if you need help with that.
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your wonderful help. The solution is quick, smooth... and most importantly, works.