SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2012
    0 Post(s)
    0 Thread(s)

    In one table join2 fields and put result into 3rd field (actually want to join 4)


    This is my first post. I am not a programmer but I like to play with databases (I have access to them as part of my real job - don't worry I only ever work in test environments)

    I have a table in a sql 2008 database. I want to create a unqiue identity for each record based on the information in 4 fields combined.

    Table 1

    Field 1
    Field 2
    Field 3
    Field 4
    Field 5

    After a copy of data (bcp - just learnt how to do that) into the table I have

    Field 1 = A
    Field 2 = B
    Field 3 = C
    Field 4 = 1
    Field 5 = NULL

    work some programming magic (this is what I want from the forum)

    Field 5 = A B C 1

    This is for all the records - maximum will be about 200 records at any one time.

    This is to run in a stored procedure.

    As, I mentioned I am not a programmer. I have spent many hours trying to do this and just don't know what I am doing.

    Can someone give me the answer. I have browsed the web and forums and can't find out how to do it.

    Thanks in anticipation

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Toronto, Canada
    63 Post(s)
    3 Thread(s)
    UPDATE daTable
       SET Field5 = '' + Field1 + Field2 + Field3 + Field4
    you did not specify column datatypes, so the empty string at the start is to coerce concatenation | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Apr 2012
    0 Post(s)
    0 Thread(s)
    Hello r937,

    That worked fine. I don't want you think that I just came to the forum without doing any work - I tried this and other things; I must have just been confused. Below is some of the bits of code I was playing with to try and succeed.

    I will move on now and continue with my objective.

    Thank you for your help.


    SET DescptAndLog = concat(@DESC + @LOGNO)

    declare @v1 varchar(50)
    declare @v2 varchar(12)
    select @v1 = 'test', @v2='a' select cast(@v1 as CHAR(50)) + @v2

    /*join attempt 2*/
    DECLARE @Dal [NCHAR] (20)
    SELECT (id) + ',' + (descpt) + ', ' + (logno) as dal from OEEImp24

    SELECT @Dal = (id) + ',' + (descpt) + ', ' + (logno) FROM OEEImp24

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts