You must Sign In to post a response.
  • Category: SQL Server

    How to combine the two columns in sql server

    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
  • #762500
    Hi

    you can try this Query for Combine Columns

    Sql Query






    CREATE TABLE tblDet
    (
    Col1 varchar(30),
    Col2 varchar(30),
    Col3 varchar(30)
    )

    Insert into tblDet values('A1','B1','C1')
    Insert into tblDet values('A2','B2','C2')
    Insert into tblDet values('A3','B3','C3')

    Select Col1 + '/' + col2 + '/' + col3 from tblDet





    I have attached snap shot given below.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment

  • #762506
    Hi,

    Before concatenate table columns, make sure both columns datatypes should be same, if any one column datatype is differ then convert that into your desired format.

    This is the sample one to concatenate your columns.

    select column1+" "+column2 from tablename


    Hope this will helpful to you..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762971
    SELECT column1 + column2 AS column3
    FROM table;

    Or you can also try this...

    select concat(column1, column2)

  • #763301
    Hello,

    Seems that it's like a concatenation of two field values.
    Try with below SQL query :-

    select BatchID, Cid, convert(varchar(50), BatchID) + '/' + convert(varchar(50),Cid) as Batch from
    (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') as tbl

    Hopefully the above query helps you a lot.
    Try with this.

    Thanks


Sign In to post your comments