I'm working on a query that copies the table structure from a linked server into the local database for a generic list of tables.
However for some reason the decimal data types are getting changed to numeric. This only seemed to be happening when selecting into over linked servers. However when trying the same on my local system I could not replicate the problem.
The environment where this error happened the SQL version of the local and linked server were different (10, 12 respectively). Not sure if that's related.
If anyone could shed some light on this it would be much appreciated. Thanks.
The query is as per below:
WHILE (select count(*) from @tbls) > 0
BEGIN
SELECT @id = 0, @tblname = '', @cols = '', @colSets = ''
select top 1 @id = ID, @tblname = TableName, @PKField = PKField, @DataType = DataType from @tbls
if exists (select 1 from sys.tables where name = @tblname)
begin
delete from @tbls where ID = @id
Continue;
end
exec('select * into '+ @tblname +' from [linkedserver].MyDatabase.dbo.'+@tblname + ' where 1 = 0')
delete from @tbls where ID = @id
END