Getting Status using Case statements in SQL Server 2008 -
i new dba created inventory check stored procedure. need check obsolete , inventory on hand column , have results impact status column on client table. here illustration of code i'm using.
insert dbo.tblcsscustdeferred_testnew ([contacttype] ,[contactid] ,[title] ,[lastname] ,[firstname] ,[minit] ,[addr1] ,[addr2] ,[city] ,[state] ,[zip] ,[qty] ,[opid] ,[beneset] ,[rideroption] ,[seqnum] ,[lob] ,[formidnum] ,[formdescr] ,[entityname] ,[attn] ,[empgrpid] ,[networkcode] ,[brand] ,[formsmgmtnum] ,[formsmgmtdesc] ,[electronic] ,[letterhead] ,[envelope] ,[language] ,[jurisdiction] ,[effective date] ,[status]) select [contacttype] ,[contactid] ,[title] ,[lastname] ,[firstname] ,[minit] ,[addr1] ,[addr2] ,[city] ,[state] ,[zip] ,[qty] ,[opid] ,[beneset] ,[rideroption] ,[seqnum] ,[lob] ,[formidnum] ,[formdescr] ,[entityname] ,[attn] ,[empgrpid] ,[networkcode] ,[brand] ,[formsmgmtnum] ,[formsmgmtdesc] ,[electronic] ,[letterhead] ,[envelope] ,[language] ,[jurisdiction] ,[effective date] case when tsg.obsolete = 'n' 'oos' when tsg.[inventory on hand] = '0' 'oos' else 'fulfilled' end case when tsg.obsolete = 'y' 'n/a' when tsg.[inventory on hand] > 0 'completed' else 'oos' end ,[status] [cssfulfillment].[dbo].[tblcsscustupdatetest] cust left bring together [cssfulfillment].[dbo].[tmptsginventoryimport] tsg on cust.formidnum = tsg.[item id] end my problem query throwing syntax error can not find. here's error message;
msg 156, level 15, state 1, line 68 wrong syntax near keyword 'case'.
i have tired looking online no avile. hoping can lean eyeball , help me.
thanks in advance help on this.
missing comma between fields , case statements....
updated answer.
just run select statement see if ruturn results. seek insert table. please @ ,b column , replace want names.
insert dbo.tblcsscustdeferred_testnew ([contacttype] ,[contactid] ,[title] ,[lastname] ,[firstname] ,[minit] ,[addr1] ,[addr2] ,[city] ,[state] ,[zip] ,[qty] ,[opid] ,[beneset] ,[rideroption] ,[seqnum] ,[lob] ,[formidnum] ,[formdescr] ,[entityname] ,[attn] ,[empgrpid] ,[networkcode] ,[brand] ,[formsmgmtnum] ,[formsmgmtdesc] ,[electronic] ,[letterhead] ,[envelope] ,[language] ,[jurisdiction] ,[effective date], a, b -- replace , b column ,[status]) select [contacttype] ,[contactid] ,[title] ,[lastname] ,[firstname] ,[minit] ,[addr1] ,[addr2] ,[city] ,[state] ,[zip] ,[qty] ,[opid] ,[beneset] ,[rideroption] ,[seqnum] ,[lob] ,[formidnum] ,[formdescr] ,[entityname] ,[attn] ,[empgrpid] ,[networkcode] ,[brand] ,[formsmgmtnum] ,[formsmgmtdesc] ,[electronic] ,[letterhead] ,[envelope] ,[language] ,[jurisdiction] ,[effective date] , case when tsg.obsolete = 'n' 'oos' when tsg.[inventory on hand] = '0' 'oos' else 'fulfilled' end , case when tsg.obsolete = 'y' 'n/a' when tsg.[inventory on hand] > 0 'completed' else 'oos' end ,[status] [cssfulfillment].[dbo].[tblcsscustupdatetest] cust left bring together [cssfulfillment].[dbo].[tmptsginventoryimport] tsg on cust.formidnum = tsg.[item id] sql-server-2008
No comments:
Post a Comment