我一直得到bcp错误

时间:2013-10-18 06:05:00

标签: sql-server-2008 tsql

任何人都可以告诉我这里我做错了什么?我试图根据我操作的数据查询到平面文件。我一直收到以下代码的错误。 感谢您的所有帮助!

任何人都可以告诉我这里我做错了什么?我试图根据我操作的数据查询到平面文件。我一直收到以下代码的错误。 感谢您的所有帮助!

   declare variables....

    select @effDate = effective_date from c_flt_src 

    if convert(varchar(10), @effDate, 112) = convert (varchar(10), GETDATE(),112)
        set @sqleffdate = convert(varchar(10), @effDate, 112)
        begin
            select @all = store from c_flt_src where store = 'ALL'

                if @@ROWCOUNT = 1 and @all = 'ALL'
                    select @action = action from c_flt_src 
                        if @action = 'INCREASE' or @action = 'DECREASE'
                            set @actiontyp = 'UPDATE_STORE'
                        else if @action = 'REPLACE'
                            set @actiontyp = 'RESET_STORE'


                    select @a = a_amt from c_flt_src 
                    select @b = b_amt from c_flt_src 

                    begin
                        declare @c as cursor
                        set @c = CURSOR fast_forward for select distinct top 3 store from store_loc where store <> 0 order by store 
                            open @c
                                fetch next from @c into @store
                                    while @@FETCH_STATUS  = 0
                                        begin
                                            --process data here
                                            set @sql = @sqlaction + '|' + @actiontyp + '|' + @store + '|' + @a + '|' + @b  
                                            set @sql1 = '"'+'D:\file.'+@sqleffdate+'.9999999.'+REPLICATE ('0', 3-LEN(@store)) +  @store +'.deltaloc' + '"'
                                            select @sql1 
                                            declare @s varchar(max)
                                            set @s = ''''+'bcp "select ''''' +  @sql + '''''"' + ' queryout ' + @sql1+ ' -c -t "|" -T'+''''
                                            select @s
                                            execute master.dbo.xp_cmdshell @s 

                                    fetch next from @c into @store
                                        end
                            close @c
                            deallocate @c

                    end


        end

1 个答案:

答案 0 :(得分:0)

尝试将@s的声明替换为varchar(4000)varchar(8000)而非varchar(max)

declare @s varchar(4000)

xp_cmdshell (Transact-SQL)

  

<强> command_string

     

包含要传递给操作的命令的字符串   系统。 command_string是varchar(8000)或nvarchar(4000),没有   默认值。