November 30, 2006 at 10:12 am
Hi I am inserting data into a table using the following query
Select ADD_OP, ADD_DATE, EDIT_OP, EDIT_DATE,'n','202', LR_REV,END_DATE, '0', W_SHIFT, LR_REX FROM W_SOURCE INNER JOIN LR ON LR_RES = W_RES
I would like to concatenate LR_REV with one unique value. If I have played around and wondered if I added an inner join say select top 100 percent to the query would that give me the field I could concatenate to LR_REV?.
Thanks.
November 30, 2006 at 12:17 pm
I'm not real sure exactly what you are trying to do, but it sounds like a great place for a scalar function. When you say "I would like to concatenate LR_REV with one unique value", what exactly do you mean? What type of unique value? Can you give an example and include some sample data?
December 1, 2006 at 1:50 am
ADD_OP, ADD_DATE, EDIT_OP, EDIT_DATE,'n','202', LR_REV,END_DATE, '0', W_SHIFT, LR_REX
The basic data would be :-
SYS, 01/12/2006, SYS, 01/12/2006,n,2002,MCHN1,02/12/2006,0,SHIFT1,END
I would like the proposed data to be :-
SYS, 01/12/2006, SYS, 01/12/2006,n,2002,MCHN1 + UNIQUE ID ,02/12/2006,0,SHIFT1,END
Is this possible?
December 1, 2006 at 3:27 am
what would you like for the UNIQUE ID. Should it be a numeric in the increasing order or it would be any alpha numeric value.
cheers
December 1, 2006 at 4:08 am
Hi, The additional field should be a numeric.
December 1, 2006 at 7:59 am
December 1, 2006 at 8:14 am
Hi John,
I would prefer a sequential numeric field
December 1, 2006 at 8:44 am
I think you’re going to have a problem with this solution. While you may be able to get something that works, it may be best to re-think the design of your table. Can you give us some more information as to what you are trying to accomplish and the business rules surrounding your problem?
You can surely come up with a method to concatenate a unique sequential number onto your LR_REV column (varchar (??) I assume), but you run into a couple of problems in doing this. First, how do you truly enforce uniqueness of the concatenated value? In order to ensure that the value you are concatenating has not yet been used in the table, you would need to check the existing values first (I would use an outer join in my insert). The problem with this is that the value you want to check for is at the end of the column’s data which means even if you index this column, it will be a table scan each time you insert. I hope I’m making sense here. Why can’t you just add an identity column to your table? If you need to display the LR_REV value along with the identity, handle that in a subsequent select or in your application.
December 1, 2006 at 9:02 am
Hi,
Here's my query, I really would appreciate it if you could help me.
Thanks,
SELECT
WT_ADD_OP, WT_ADD_DATE, WT_EDIT_OP,, WT_EDIT_DATE, 'N', '211', ,
LR_REV, WT_END_DATE, '0', WT_SHIFT, LR_REV, '20061212', DATEADD(Second,
(FLOOR(LR_DAY_END_TIME / 10000) * 3600) +
(FLOOR((LR_DAY_END_TIME - (FLOOR(LR_DAY_END_TIME / 10000) * 10000)) / 100) * 60) +
(LR_DAY_END_TIME - ((FLOOR(LR_DAY_END_TIME / 100) * 100))),
CONVERT(datetime, WT_END_DATE)) AS 'actl_end_dt_tm',
'0' -- [shft_use_end_tm] [smallint] NULL
FROM WT
INNER JOIN LR ON LR_RES = WT_RES
December 1, 2006 at 9:23 am
I suggest you think about re-designing your approach, but if you insist to go down this route, check out these two threads. The first one in particular should be helpfull.
http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=316818&p=1
http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=318870
December 1, 2006 at 3:08 pm
As the two links John posted suggest, add an IDENTITY column to your table and concatenate with the string conversion of that.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply