SQL
Nguyen SVN > 29-11-19, 09:45 AM
'--------------------------------------------------------------------
'---CREATE DATE : 2019/11/29 Nguyen
'---------------------------------------------------------------
CREATE PROCEDURE [dbo].[Combo_01]
(
@Table VARCHAR(100),
@Column VARCHAR(100)
)
AS
DECLARE @SORT VARCHAR(100)
IF @Column LIKE '%Year' OR @Column LIKE '%Day%'
SET @SORT = '1 DESC'
ELSE
SET @SORT = '1'
--
EXEC( '
SELECT *
FROM (
SELECT CASE WHEN ISDATE( ' + @Column+ ' ) = 0 THEN ' + @Column+ ' ELSE CONVERT( VARCHAR(10), ' + @Column + ', 111 ) END AS [' + @Column + ']
FROM ' + @Table + '
WHERE ' + @Column + ' IS NOT NULL
) AS AA
GROUP BY [' + @Column + ']
ORDER BY ' + @SORT
)
RETURN