问题
I have the following SQL Statement
SELECT DISTINCT CAST(CONVERT(CHAR(16), AuditDate,113) AS datetime), DisplayName
FROM myTable
WHERE DisplayName IS NOT NULL
ORDER BY DisplayName asc
The two columns that get returned as Display name
and (No Column Name)
with the latter being a problem. I'm using this in an SSRS report and I need to pass my AuditDate value to it. With result now being (No Column Name)
my report has missing information.
How can i fix this?
回答1:
Give your column an alias like this:
SELECT DISTINCT CAST(CONVERT(CHAR(16), AuditDate,113) AS datetime) AS 'Audit Date'
or
SELECT DISTINCT CAST(CONVERT(CHAR(16), AuditDate,113) AS datetime) 'Audit Date'
depending on your preferred syntax
回答2:
Just add alias to result column
CAST(CONVERT(CHAR(16), AuditDate,113) AS datetime) AS [AuditDate]
回答3:
SELECT DISTINCT
CAST(CONVERT(CHAR(16), AuditDate,113) AS datetime) AS AuditDate,
DisplayName
FROM
myTable
WHERE
DisplayName IS NOT NULL
ORDER BY
DisplayName ASC
来源:https://stackoverflow.com/questions/45549289/sql-convert-no-column-name