Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ben53
Starting Member
2 Posts |
Posted - 2013-05-07 : 19:31:47
|
DROP TABLE #ABCCREATE TABLE #ABC (ID INT, Name VARCHAR (2))INSERT INTO #ABC (ID, NAME)VALUES (1,'01'),(1,'F5'),(1,'05'),(2,'08'),(2,'G4'),(3,'Y7'),(3,'18') DROP TABLE #DEFCREATE TABLE #DEF (ID INT, Name char(20))INSERT INTO #DEF (ID, Name)SELECT ID, SUBSTRING(REPLACE(CONVERT(VARCHAR(36), NEWID()) , '-', ''), 1, 2) AS Name FROM #ABCDROP TABLE #XYZCREATE TABLE #XYZ (ID INT, Name char(20))INSERT INTO #XYZ (ID, Name)SELECT #DEF.ID, #DEF.Name FROM #DEFLEFT JOIN #ABC ON #ABC.ID = #DEF.ID AND #ABC.Name = #DEF.NameWHERE #ABC.ID IS NULLSELECT * FROM #XYZI want the process to create a new 'name' which is already not taken by the same ID. in other words, same ID (say ID =1) can not have the same "Name" columns. This is just very few records but my real data is huge, I want system to generate only new Names with 2 characters in table#XYZ which are already not taken by the same ID in #ABC. Also, number of records inserted in #XYZ should be equal to #ABC Any help is appreciated. Thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-08 : 00:50:20
|
sounds like what you need a customer sequence based on ID field. You can still have same Name for different Ids right?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
ben53
Starting Member
2 Posts |
Posted - 2013-05-08 : 00:52:35
|
Yes we can have same Names for different IDs |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
zhulin
3 Posts |
Posted - 2013-05-08 : 09:31:42
|
You need more of the statements in this matter, so that we can understand. Thank you for sharing. I hope you happy__________________zhulinunspammed |
 |
|
|
|
|
|
|