生成导入MYSQL的视图 不断更新中

USE liebotest
GO

DECLARE @s VARCHAR(8000)='',@tb VARCHAR(128)='OrderFlow.[Order]'

SELECT @s=@s+',
'+(CASE WHEN b.NAME='datetime' THEN
'convert(datetime,convert(varchar(19),'+QUOTENAME(a.NAME)+',20)) as ' ELSE '' END )+

QUOTENAME(a.NAME) FROM sys.all_columns a INNER JOIN sys.types b
ON a.user_type_id=b.user_type_id
WHERE a.object_id=object_id(@tb)

SET @s='
create view '+OBJECT_NAME(OBJECT_ID(@tb))+'_VV_To_MySQL2
as
select '+STUFF(@s,1,1,'')+'
from '+@tb
exec(@s)

 

 

你可能感兴趣的:(生成导入MYSQL的视图 不断更新中)