日期:2014-05-17 浏览次数:20404 次
SELECT a.SystemContractID,
a.Income,
a.TotalMargin,
a.UserCode,
a.StrategyID,
ISNULL(b.StrategyName,a.StrategyID) StrategyName
FROM OrderProfit_History as a
INNER JOIN Strategy as b
ON a.StrategyID = b.StrategyID
if object_id('OrderProfit_History', 'u') is not null
drop Table OrderProfit_History
Create Table OrderProfit_History
(
ID int identity(1, 1) primary key not null,
StrategyID int not null,
OrderID int not null
)
Insert into OrderProfit_History
Select 1, 2
Union all Select 2,2 Union all Select 3,3
Union all Select 4,4
Union all Select 5,5
Union all Select 6,6
Union all Select 7,7
Union all Select 8,8
if OBJECT_ID('Strategy', 'u') is not null
drop table Strategy
Create Table Strategy
(
ID int identity(1, 1) primary key not null,
StrategyID int not null,
StrategyName varchar(128) not null
)
Insert into Strategy
Select 1, 'aaaa'
Union all Select 2,'bbbb'
Union all Select 3,'cccc'
Union all Select 4,'dddd'
Select a.StrategyID,
ISNULL(b.StrategyName, CONVERT(Varchar(32), a.StrategyID)) as StrategyName
From OrderProfit_History a Left Outer Join Strategy b On a.StrategyID = b.StrategyID