DECLARE @temp TABLE
(
iLeadID INT ,
Title VARCHAR(MAX) ,
AlertDate DATETIME
)
DECLARE @iLeadID INT
DECLARE @getiLeadID CURSOR
SET
@getiLeadID = CURSOR FOR
SELECT iLeadID FROM LeadsContracts
OPEN @getiLeadID
FETCH NEXT FROM @getiLeadID INTO @iLeadID
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @temp
SELECT @iLeadID ,
'Disclosure' ,
CONVERT(VARCHAR, dtDisclosure, 101) 'Date'
FROM LeadsContracts
WHERE iLeadID = @iLeadID
AND dtDisclosure IS NOT NULL
INSERT INTO @temp
SELECT @iLeadID ,
'Due Diligence' ,
CONVERT(VARCHAR, dtDueDiligence, 101) 'Date'
FROM LeadsContracts
WHERE iLeadID = @iLeadID
AND dtDueDiligence IS NOT NULL
INSERT INTO @temp
SELECT @iLeadID ,
'Finance Appraisals' ,
CONVERT(VARCHAR, dtFinanceAppraisals, 101) 'Date'
FROM LeadsContracts
WHERE iLeadID = @iLeadID
AND dtFinanceAppraisals IS NOT NULL
INSERT INTO @temp
SELECT @iLeadID ,
sFreeTextCustom1 ,
CONVERT(VARCHAR, dtFreeTextDate1, 101) 'Date'
FROM LeadsContracts
WHERE iLeadID = @iLeadID
AND dtFreeTextDate1 IS NOT NULL
INSERT INTO @temp
SELECT @iLeadID ,
sFreeTextCustom2 ,
CONVERT(VARCHAR, dtFreeTextDate2, 101) 'Date'
FROM LeadsContracts
WHERE iLeadID = @iLeadID
AND dtFreeTextDate2 IS NOT NULL
FETCH NEXT FROM @getiLeadID INTO @iLeadID
END
CLOSE @getiLeadID
DEALLOCATE @getiLeadID
SELECT * ,
( CASE WHEN 1 = 1
THEN ( SELECT TOP 1
sEmail
FROM UserAccount objUA
WHERE EXISTS ( SELECT iUserID
FROM GroupAgent
WHERE iUserID = objUA.iUserID
AND iGroupID = t1.GroupID
AND btAdminFlg = ( (1) ) )
)
ELSE ''
END ) AS AdminEmail
FROM ( SELECT * ,
CASE WHEN 1 = 1
THEN ( SELECT TOP 1
sFirstName + ' ' + sLastName
FROM Lead
WHERE iLeadID = objTemp.iLeadID
)
ELSE ''
END AS LeadName ,
CASE WHEN 1 = 1
THEN ( SELECT TOP 1
sEmail
FROM Lead
WHERE iLeadID = objTemp.iLeadID
)
ELSE ''
END AS LeadEmail ,
CASE WHEN 1 = 1
THEN ( SELECT TOP 1
iUserID
FROM AssignLeadUser
WHERE iLeadID = objTemp.iLeadID
)
ELSE ''
END AS AgentID ,
CASE WHEN 1 = 1
THEN ( SELECT TOP 1
sFirstName + ' ' + sLastName
FROM UserAccount
WHERE iUserID = ( SELECT
iUserID
FROM AssignLeadUser
WHERE iLeadID = objTemp.iLeadID
)
)
ELSE ''
END AS AgentName ,
CASE WHEN 1 = 1
THEN ( SELECT TOP 1
sEmail
FROM UserAccount
WHERE iUserID = ( SELECT
iUserID
FROM AssignLeadUser
WHERE iLeadID = objTemp.iLeadID
)
)
ELSE ''
END AS AgentEmail ,
CASE WHEN 1 = 1
THEN ( SELECT TOP 1
iGroupID
FROM AssignLeadUser
WHERE iLeadID = objTemp.iLeadID
)
ELSE ''
END AS GroupID ,
CASE WHEN 1 = 1
THEN ( SELECT TOP 1
sName
FROM [Group]
WHERE iGroupID = ( SELECT
iGroupID
FROM AssignLeadUser
WHERE
iLeadID = objTemp.iLeadID
)
)
ELSE ''
END AS GroupName
FROM @temp objTemp
) AS t1
ORDER BY AlertDate ASC
它给了我列2013-04-04 00:00:00.000
中的输出AlertDate
我只想得到这样的日期(没有时间):2013-04-04
“ 在AlterDate
列中。
有人可以帮我提出一些查询或更新我的代码吗?
提前致谢