Hi @AbdulWahab Khan
Check this query:
;WITH CTE AS
(
SELECT Table_Name,ORDINAL_POSITION,CASE WHEN Data_Type ='datetime' THEN 'cast('+Column_Name+' as date)'ELSE Column_Name END AS Column_Name
FROM INFORMATION_SCHEMA.COLUMNS
)
SELECT 'select '
+ STUFF((select ', ' + column_name from CTE
where Table_Name = c.Table_Name
order by ORDINAL_POSITION
for xml path('') ), 1, 2, '')
+ ' from '
+ Table_Name AS query
FROM CTE C
GROUP BY Table_Name
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.