在表格中添加动态列.... [英] adding a dynamic column in a table....

查看:90
本文介绍了在表格中添加动态列....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在运行时向表中添加列。这假设我有一个包含4列的表...我已经为insert,del,upd操作编写了一个存储过程。现在我想要的是不使用alter语句,当我自动编写选择查询时,我得到一个额外的列,它应该具有对应empid的价值。对于empid 100,102我得到第一个,第一个等等...

试了一下,但是进了两天......请帮我出去。提前谢谢。







先生我有一个表有4列名为empid,emp_name,emp_ADD,emp_Phno.now的表我创建了一个插入,删除,更新,搜索操作的过程。我的表格如下:

is there any way to add a column to a table during runtime. That is suppose i have a table containing 4 columns...i have written a stored procedure for insert,del,upd operations also. now what i want is without using alter statement when i write select query automatically i get a additional column and it should have values corresponding to empid..ie for empid 100,102 i get first,first and so on...
tried it but struck in it for two days ...help me out.thanks in advance.



sir i have a table that have 4 columns named empid,emp_name,emp_ADD,emp_Phno.now i have created a procedure to insert,delete,update,search operation. my table is as follows:

empid	emp_name  Add	emp_phno
100	rachit	 516-a	8696953366	
101	ush	 25/a	7737708131
105	unnet	 sfgcsy	986547896 	
104	bobby	 76A	7899877899	
103	dharam	 2519	7765477654	
102	kishor	 77/A	8989689896	





现在不使用任何改变命令..我想在使用select * from employee
时想要这个



Now without using any alter command ..i want this when use select * from employee

empid	emp_name  Add	emp_phno      grp_emp
100	rachit	 516-a	8696953366	first
101	ush	 25/a	7737708131      first
105	unnet	 sfgcsy	986547896 	second
104	bobby	 76A	7899877899	second
103	dharam	 2519	7765477654	third
102	kishor	 77/A	8989689896	third





i想要在运行时添加最后一列而不使用alter语句。我认为这对你的sir.thanks来说已经足够了。 />


[/ EDIT]



i want to add this last column on runtime without using alter statement.I think this is sufficient for u sir.thanks.

[/EDIT]

推荐答案

select empid, (case when  empid between 1 and 2 then 'first'  when  empid=3 then 'second' else 'other' end ) as groupname   from employee_test





这也可以尝试。这两个解决方案对我有用。



This can be tried also. Both solutions worked for me.


我不确定你想要实现什么...

I''m not sure what you want to achieve...
Maciej Los - 写道:
Maciej Los - wrote:



根据您希望在群组中划分员工的条件?


Based on which condition do you want to divide employees on groups?

R_sharma - 前写道:
R_sharma - ago wrote:



任何条件先生。我没有得到解决这个问题的关键。你可以指导我接近这个和这类问题。谢谢


any condition sir. i am not getting key to solve this question. could you please guide me to approach this and this type of questions.thanks





任何的例子(其中任何表示: empid modulo 2 )对员工进行分组的条件:



Example for "any" (where "any" means: empid modulo 2)condition to group employees:

SELECT empid, emp_name, [Add], emp_phno, CONVERT(INT, (empid % 2) +1 ) AS grp_emp
FROM @emp
ORDER BY CONVERT(INT, (empid % 2) +1 )





结果:



Result:

100	rachit	516-a	8696953366	1
104	bobby	76A	7899877899	1
102	kishor	77/A	8989689896	1
103	dharam	2519	7765477654	2
101	ush	25/a	7737708131	2
105	unnet	sfgcsy	986547896	2


这篇关于在表格中添加动态列....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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