Zerotoinfinity
Zerotoinfinity

Reputation: 6530

Getting correct data type of columns from view

I am trying to create a table from view. This view is from a join between multiple tables. But in the target table almost all columns have either Varchar(8000) or NVARCHAR(4000) which is not true for any of the columns. I tried to get the structure via

SELECT * INTO targetTable from SourceView

&

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE Table = 'SourceView'

both are giving me varchar and nvarchar datatype with very high range.

What is the correct way to get the source column data type?

enter image description here

Upvotes: 3

Views: 2364

Answers (1)

sagi
sagi

Reputation: 40481

I don't know if its the best solution performance wise , but you can just cast them in the select fields..

CREATE VIEW ...
SELECT CAST(DesiredColumn as varchar(50)) as DesiredColumn,
       ....

Upvotes: 1

Related Questions