SQL Server Performance

Why this SQL Query is not working.

Discussion in 'General Developer Questions' started by Sailu, Mar 31, 2005.

  1. Sailu New Member


    Hi friends,

    I have a code like this. when i execute in Query analyser I am getting Error. Please advise me.


    Declare
    @cmd sysname,
    @rc int,
    @var1 nvarchar(500)


    Set @var1='SELECT au_fname, au_lname FROM pubs..authors where au_fname'+SPACE(1)+'='+'''Abraham'''
    print @var1
    set @cmd='bcp'+SPACE(1)+@var1+SPACE(1)+'queryout'+SPACE(1)+'Authors19.txt'+SPACE(1)+'-c'+SPACE(1)+'-SLocalhost'+SPACE(1)+'-Usa'+SPACE(1)+'-Psa'
    print @cmd
    exec @rc=master..xp_cmdshell @cmd

    Regds
    Sailu
  2. Argyle New Member

    Put " around your query and remove the queryout word like this:

    Declare
    @cmd sysname,
    @rc int,
    @var1 nvarchar(500)


    Set @var1='"SELECT au_fname, au_lname FROM pubs..authors where au_fname'+SPACE(1)+'='+'''Abraham''"'
    print @var1
    set @cmd='bcp'+SPACE(1)+@var1+SPACE(1)+' out'+SPACE(1)+'Authors19.txt'+SPACE(1)+'-c'+SPACE(1)+'-SLocalhost'+SPACE(1)+'-Usa'+SPACE(1)+'-Psa'
    print @cmd
    exec @rc=master..xp_cmdshell @cmd

Share This Page