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

Hello,

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

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

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.

SolarFlare

UPDATE OEEImp24
SET DescptAndLog = concat(@DESC + @LOGNO)

set
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