如何更新SQL Server 2008中动态生成的列 [英] how to update dynamically generated columns in sql server 2008

查看:180
本文介绍了如何更新SQL Server 2008中动态生成的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个临时表,其中的数据列是使用数据透视表动态生成的.当我使用数据透视表功能时,这些列本身就是int数据类型.列的值为0或1.现在,我想用"Y"更新1,用"N"更新0.但这样做时出现转换错误.请帮忙.




当我将行透视成列时,列会自动转换为使用的count函数的int数据类型bcoz,因此所有列(@cols)的值都为0和1.现在我要执行更新操作.

I have a temporary table in which the columns are dynamically generated using pivot.As I am using the pivot function the columns by themselves are of int datatype. the values for the columns are either 0 or 1. Now I want to update 1 with ''Y'' and 0 with ''N''. but I am getting conversion error while doing so. please help.




When I am pivoting the rows into columns the columns are automatically getting converted to int datatype bcoz of count function used, so all the columns (@cols) are having 0 and 1 values. now i wantto perform the update operation.

推荐答案

由于您未发布该语句,因此很难说出为什么要进行转换错误,但要更改值,可以使用 CASE [
Since you didn''t post the statement it''s quite hard to say why you''re getting a conversion error but to change the values you could use CASE[^]

Addition:

Based on the statement you added, looks like you''re just updating the column value to ''Y''. What is the underlying data type? If it is a number, then you would receive the conversion error.


这篇关于如何更新SQL Server 2008中动态生成的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆