此查询有什么问题?此外,我尝试使用(选择前100%)它有效但无效。
ALTER VIEW [dbo].[viewTblDaily]
AS
SELECT
tblTasks.TaskID,TUsers.UserFirstName + ' ' + TUsers.UserLastName AS [UserFullName],
TTasksType.TaskDescription AS TaskType,
CONVERT(NVARCHAR, tblTasks.DateTask, 103) DateTask,
tblTasks.TimeTask,
tblTasks.TaskDescription,
tblTasks.statusTask,
TUsers.UserID AS [userID]
FROM
tblTasks
LEFT JOIN
tblTaskType AS TTasksType ON tblTasks.TaskTypeID = TTasksType.TaskID
LEFT JOIN
tblUsers AS TUsers ON TUsers.UserID = tblTasks.UserID
WHERE
CONVERT(VARCHAR(10), tblTasks.DateTask, 102) = CONVERT(VARCHAR(10), getdate(), 102)
AND tblTasks.StatusTask = 0
ORDER BY
TaskID
答案 0 :(得分:0)
视图不是DB中的实际表。 (实际上MySQL DB也不喜欢有序的表定义) 它仅作为等待您使用它的架构存在。 订购无关
答案 1 :(得分:-1)
我建议你这个
ALTER VIEW [dbo].[viewTblDaily]
AS
SELECT
tblTasks.TaskID,TUsers.UserFirstName + ' ' + TUsers.UserLastName AS [UserFullName],
TTasksType.TaskDescription AS TaskType,
CONVERT(NVARCHAR, tblTasks.DateTask, 103) DateTask,
tblTasks.TimeTask,
tblTasks.TaskDescription,
tblTasks.statusTask,
TUsers.UserID AS [userID],
ROW_NUMBER() OVER (ORDER BY TaskID) As RowNum
FROM
tblTasks
LEFT JOIN
tblTaskType AS TTasksType ON tblTasks.TaskTypeID = TTasksType.TaskID
LEFT JOIN
tblUsers AS TUsers ON TUsers.UserID = tblTasks.UserID
WHERE
CONVERT(VARCHAR(10), tblTasks.DateTask, 102) = CONVERT(VARCHAR(10), getdate(), 102)
AND tblTasks.StatusTask = 0
您会看到其结果将由RowNum
订购,或者在选择后您也可以使用RowNum
保证结果的顺序。