solarflare — 2012-04-28T03:30:06-04:00 — #1
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.
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
r937 — 2012-04-28T07:01:37-04:00 — #2
SET Field5 = '' + Field1 + Field2 + Field3 + Field4
you did not specify column datatypes, so the empty string at the start is to coerce concatenation
solarflare — 2012-05-05T08:36:06-04:00 — #3
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