sql - sqlException (0x80131904) The name'...' is not a valid identifier -


i have stored procedure dynamic based on database needs access. running procedure program gives me error:

system.data.sqlclient.sqlexception (0x80131904): name '...' not valid identifier.....

when run stored procedure ssms, same error, if print instead of exec, run code manually, works fine.

declare @sql varchar(8000) if @provider=''     set @sql = '     update  ' + @linkserver + '.dbo.[billing header] set [bill primary]=1 billing in(     select distinct billing  ' + @linkserver + '.dbo.[history detail]      ' +  @wheredatefacility  + ' , [insurance code] = rtrim( '''+ @primarycode +''')); select @@rowcount rc;' else     set @sql = '     update  ' + @linkserver + '.dbo.[billing header] set [bill primary]=1 billing in(     select distinct hd.billing  ' + @linkserver + '.dbo.[history detail] hd         inner join ' + @linkserver + '.dbo.[billing header] bh on bh.billing=hd.billing     provider=''' + @provider + ''' , ' +  @wheredatefacility  + ' , [insurance code] = rtrim( '''+ @primarycode +''')); select @@rowcount rc;' end  insert dbo.[log] ([desc]) values(@sql)  --print @sql exec @sql 

pulling code snippet log works fine too. here final code log works fine if ran manually.

update [targetdb].dbo.[billing header]  set [bill primary] = 1  billing in (select distinct billing                    [targetdb].dbo.[history detail]                    [date printed] = '04/22/2014'                      , [insurance code] = rtrim( 'med001')); select @@rowcount rc; 

any ideas can done fix this?

thanks, dave k.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -