日期:2014-05-17 浏览次数:20526 次
INSERT INTO @tabResult (ContractCode,SD_State_InOut,First_Map,ContractName,AlterMoney,SignDate,ContractState) CASE WHEN @ContractType = '1' THEN SELECT a.ContractCode,a.SD_State_InOut,a.ContractName,a.AlterMoney,a.SignDate,a.ContractState,b.ConsumerName AS First_Map FROM BS_Contract AS A left join OA_Consumer AS B ON A.First = B.ID WHERE A.ID = @ContractID WHEN @ContractType = '0' THEN SELECT a.ContractCode,a.SD_State_InOut,a.ContractName,a.AlterMoney,a.SignDate,a.ContractState,b.ConsumerName AS First_Map FROM BS_Contract_AUDIT AS A left join OA_Consumer AS B ON A.First = B.ID WHERE A.ID = @ContractID ELSE SELECT '','','','',NULL,'','' END
if @ContractType = '1' begin INSERT INTO @tabResult (ContractCode,SD_State_InOut,First_Map,ContractName,AlterMoney,SignDate,ContractState) SELECT a.ContractCode,a.SD_State_InOut,a.ContractName,a.AlterMoney,a.SignDate,a.ContractState,b.ConsumerName AS First_Map FROM BS_Contract AS A left join OA_Consumer AS B ON A.First = B.ID WHERE A.ID = @ContractID end else begin if @ContractType = '0' begin INSERT INTO @tabResult (ContractCode,SD_State_InOut,First_Map,ContractName,AlterMoney,SignDate,ContractState) SELECT a.ContractCode,a.SD_State_InOut,a.ContractName,a.AlterMoney,a.SignDate,a.ContractState,b.ConsumerName AS First_Map FROM BS_Contract_AUDIT AS A left join OA_Consumer AS B ON A.First = B.ID WHERE A.ID = @ContractID end else begin INSERT INTO @tabResult (ContractCode,SD_State_InOut,First_Map,ContractName,AlterMoney,SignDate,ContractState) SELECT '','','','',NULL,'','' end end
------解决方案--------------------
if @ContractType = '1' insert into ... if @ContractType = '0' insert into ...
------解决方案--------------------
IF ContractType = '1' INSERT INTO @tabResult (ContractCode,SD_State_InOut,First_Map,ContractName,AlterMoney,SignDate,ContractState) SELECT a.ContractCode,a.SD_State_InOut,a.ContractName,a.AlterMoney,a.SignDate,a.ContractState,b.ConsumerName AS First_Map FROM BS_Contract AS A left join OA_Consumer AS B ON A.First = B.ID WHERE A.ID = @ContractID ELSE IF @ContractType = '0' INSERT INTO @tabResult (ContractCode,SD_State_InOut,First_Map,ContractName,AlterMoney,SignDate,ContractState) SELECT a.ContractCode,a.SD_State_InOut,a.ContractName,a.AlterMoney,a.SignDate,a.ContractState,b.ConsumerName AS First_Map FROM BS_Contract_AUDIT AS A left join OA_Consumer AS B ON A.First = B.ID ELSE INSERT INTO @tabResult (ContractCode,SD_State_InOut,First_Map,ContractName,AlterMoney,SignDate,ContractState) SELECT '','','','',NULL,'',''
------解决方案--------------------
不支持你这种写法,改为if语句
------解决方案--------------------
这种case when 是对的
case when 的结果只是一个值 不能是一个集合
------解决方案--------------------
1,用if else
2.
insert into xxxx select xxxx from xxx where xxx and @contractType='1';
insert into xxxx select xxx from xxxx where xxx and @contractType='0';
------解决方案--------------------
楼上正解 用if判断
------解决方案--------------------