• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

SQL Server获取select语句中每列的数据类型(SQL Server get data types for each colu ...

原作者: [db:作者] 来自: 网络 收藏 邀请

SQL Server获取select语句中每列的数据类型(SQL Server get data types for each column in a select statement)

我有一个proc使用临时表,然后在最后插入select语句。 我收到以下错误:

Arithmetic overflow error converting numeric to data type numeric

有没有办法可以找出select语句用于列的数据类型,以便我可以将它与临时表定义进行比较,以便我可以看到哪些列可能有问题?

我想另一种方式,我怎么能告诉哪些记录导致这个问题? 我想如果我可以在select语句的每一列中获取数据类型并与临时表进行比较,那么它将帮助我找到问题。


I have a proc that uses a temp table and then at the end inserts into that from a select statement. I'm getting the following error:

Arithmetic overflow error converting numeric to data type numeric

Is there a way that I can find out what data type the select statement is using for the columns so I can compare that to the temp table definition so I can see what column(s) may be having the issue?

I guess another way to put it, how can I tell which records are causing this problem? I figured if I could get the data type in each column in the select statement and compare to the temp table then it would help lead me to finding the issue.


原文:https://stackoverflow.com/questions/44751378
更新时间:2022-03-21 19:03

最满意答案

下面的查询将给出结果

SELECT 
    c.name 'Column Name',
    t.Name 'Data type',
    c.max_length 'Max Length',
    c.precision ,
    c.scale ,
    c.is_nullable,
    ISNULL(i.is_primary_key, 0) 'Primary Key'
FROM    
    sys.columns c
INNER JOIN 
    sys.types t ON c.user_type_id = t.user_type_id
LEFT OUTER JOIN 
    sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id
LEFT OUTER JOIN 
    sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
WHERE
    c.object_id = OBJECT_ID('TableName')

below query will give the results

SELECT 
    c.name 'Column Name',
    t.Name 'Data type',
    c.max_length 'Max Length',
    c.precision ,
    c.scale ,
    c.is_nullable,
    ISNULL(i.is_primary_key, 0) 'Primary Key'
FROM    
    sys.columns c
INNER JOIN 
    sys.types t ON c.user_type_id = t.user_type_id
LEFT OUTER JOIN 
    sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id
LEFT OUTER JOIN 
    sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
WHERE
    c.object_id = OBJECT_ID('TableName')

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap