如何合并sql中的两列 [英] how to merge the two columns in sql

查看:382
本文介绍了如何合并sql中的两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询如下



选择BatchID =(从BATCHID中选择eid,其中bid ='B16401'和b_activ =<>'d'

Cid =(从certificate_detail中选择top1 certificate_no,其中stud_id = a.stud_id,active ='A'和crsname ='ctf')

来自学生a,course_registration b,batch_course_registration c其中

a.stud_id = b.stud_id和b.cr_bill_no = c.cr_bill_no

和c.bcr_batch_id ='B16401'和b.cr_active ='A'和a .stud_active<>'D'



当我执行上述查询输出时如下



Batchid Cid

CTF / B376 09



我想结合上面的batchid和Cid并获得如下输出



Batchid Cid批次

CTF / B376 09 CTF / B376 / 09



我怎么能结合sql server中的两列

解决方案

适应:

从tablename中选择column1,column2,column1 +'/'+ column2 newcolumnname 



你可以考虑以下情况:

1. 修剪 [ ^ ]值。

2。 ISNULL [ ^ ]值。


My query as follows

select BatchID = (select eid from BATCHID where bid = 'B16401' and b_activ = <>'d'
Cid = (select top 1 certificate_no from certificate_detail where stud_id = a.stud_id and active = 'A' and crsname = 'ctf' )
from student a, course_registration b, batch_course_registration c where
a.stud_id=b.stud_id and b.cr_bill_no=c.cr_bill_no
and c.bcr_batch_id='B16401' and b.cr_active='A' and a.stud_active<>'D'

Wheni exeucte the above query output as follows

Batchid Cid
CTF/B376 09

I want to combine the above batchid and Cid and get the output as follows

Batchid Cid Batch
CTF/B376 09 CTF/B376/09

for that how can i combine the two columns in sql server

解决方案

Adapt:

select column1, column2, column1 + '/' + column2 newcolumnname from tablename


You may take into consideration the following scenarios:
1. Trimming[^] values.
2. ISNULL[^] values.


这篇关于如何合并sql中的两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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