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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 migration script needed

Author  Topic 

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2009-08-25 : 02:43:22
HI iam having two tables.


emrpreprinteditemslkup
Name Null Type
------------------------------ -------- ------------
PRE_PRINTED_ITEMS_ID NOT NULL NUMERIC(20)
PRE_PRINTED_ITEMS_NAME NOT NULL VARCHAR(50)
PRE_PRINTED_MATERIAL_NAME NOT NULL VARCHAR(50)
GROUP_ID NUMERIC(20)
FILE_NAME VARCHAR(100)
PRE_PRINTED_ITEM_STATUS NUMERIC(1)
FILE_PATH VARCHAR(500)
PRE_PRINTED_MATERIAL_ID NUMERIC(20)

8 rows selected

emrpreprintedmaterilaslkup
Name Null Type
------------------------------ -------- ---------
PRE_PRINTED_MATERIAL_ID NOT NULL NUMERIC(20)
PRE_PRINTED_MATERIAL_NAME VARCHAR(50)
GROUP_ID NUMERIC(20)
PRE_PRINTED_MATERIAL_STATUS NUMERIC(1)

4 rows selected





now i want to insert existing PRE_PRINTED_MATERIAL_ID from table B TO table A depending on group specific i,e group_id column for example it is 1501 than that particluar PRE_PRINTED_MATERIAL_ID from table B to be inserted in table A.please help me in doing this and one more condition is PRE_PRINTED_MATERIAL_NAME from both tables should match
and corresponding group_id related PRE_PRINTED_MATERIAL_ID should be inserted.

rajasekhar857
Constraint Violating Yak Guru

396 Posts

Posted - 2009-08-25 : 03:05:56
select a.PRE_PRINTED_MATERIAL_NAME,a.GROUP_ID,b.PRE_PRINTED_MATERIAL_ID,b.GROUP_ID from
emrpreprinteditemslkup a,emrpreprintedmaterilaslkup b where a.PRE_PRINTED_MATERIAL_NAME=b.PRE_PRINTED_MATERIAL_NAME
and a.group_id=b.group_id

hi i have given query like this i need to insert in table a
Go to Top of Page

IncisiveOne
Starting Member

36 Posts

Posted - 2009-08-25 : 09:48:13
You can guarantee that PRE_PRINTED_MATERIAL_NAME from both tables match by removing it entirely from the first table. Not having the duplicated column is simpler than having the duplicated column and then trying to keep it "matching".

Anything worth doing, is worth doing right.
Go to Top of Page
   

- Advertisement -