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 2008 Forums
 Transact-SQL (2008)
 how to copy particular data to other,,,

Author  Topic 

asifbhura
Posting Yak Master

165 Posts

Posted - 2011-04-29 : 08:32:36
Hello,

I have two table

table1(projectName,subProjectName etc...)

table2(ProjectID,ProjectName)

Question 1.

Now, I want to copy distinct data from table1(projectName) to table2(ProjectName)


question 2.

I want to copy data to other column
means in table1 if subprojectName is null then it will as ProjectName

means I want to copy ProjectName as SubProjectName

Regards

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-29 : 08:39:22
insert table1 (projectName,subProjectName)
select distinct projectName, projectName
from table2

or maybe
insert table1 (projectName,subProjectName)
select distinct projectName, projectName
from table2
where projectName not in (select projectName from Table1)

update table1
set subProjectName = ProjectName
where subProjectName is null

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-04-29 : 08:39:46
I think you want to UPDATE table1 with values from table2? If the subprojectname in table1 is null, then update it with the projectname from table2? Do table1 and table2 link on ProjectID or ProjectName?

JIm

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -