Saturday, October 3, 2009

sql server function to return the column datatype


select dbo.FN_COL_TYPE ('SALES.CUSTOMER','customerid')

CREATE FUNCTION FN_COL_TYPE (@TBL_NAME VARCHAR(256),@COL_NAME VARCHAR(256))
returns varchar(256)
as
begin
DECLARE @vType VARCHAR(50)

select @vType = b.name from sys.columns a join sys.types b on a.system_type_id = b.system_type_id
where object_id = object_id(@TBL_NAME)
and A.name = @COL_NAME
return @vType
end

No comments:

Post a Comment

Featured Post

SQL Server AWS Migration BCP

stored procedure to generate BCP scritps to migrate the SQL Server database. Developed this stored procedure on my labs to simulate t...

Contributors