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相信大家看到这个SQL 应该明白我的意思:
就是当 @ContractType 不同时 插入的信息也不一样
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相信大家看到这个SQL 应该明白我的意思:
就是当 @ContractType 不同时 插入的信息也不一样
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
insert into ...
if @ContractType = '0'
insert into ...
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,'',''
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';
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