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 |
|
SP273
Starting Member
14 Posts |
Posted - 2011-02-25 : 10:03:58
|
| Hello All,I am trying to write a query where in the child column in table A have a project name that is 16 characters. What i want to do is to populate a new table B in a way where in i just have first 5 letters from the child column of project name from table A. Which command can i use for this?Thanks! |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
SP273
Starting Member
14 Posts |
Posted - 2011-02-25 : 14:55:11
|
| Hi,Thanks for your reply.Below is the sample code to my queryINSERT INTO dbo.HS_Projects_Hierarchy_New( [LoadID] ,[Parent] ,[Child] ,[DataStore] ,[MemberValid1] ,[Aggregation] ,[Alias] ) ( select [LoadID] ,[Parent] ,[Child] ,[DataStore] ,[MemberValid1] ,[Aggregation] ,[Alias] from dbo.HS_Project_Hierarchy_OLD where child in ( Select distinct project from(select distinct Project from dbo.HS_Hours_Iunion allselect distinct Project from dbo.HS_Hours_II) a))Now whats the best way to modify the query so that in table HS_Projects_Hierarchy_New I just load the 5 digits project code as child & all the remaining column are populated from the table HS_Projects_Hierarchy_Old as they are being populated now.Thanks! |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
SP273
Starting Member
14 Posts |
Posted - 2011-02-25 : 16:12:07
|
| Hi,Thanks for your reply. I ran your code & modified my code as follows:INSERT INTO dbo.HS_Projects_Hierarchy( [LoadID] ,[Parent] ,[Child] ,[DataStore] ,[MemberValid1] ,[Aggregation] ,[Alias] ) ( select [LoadID] ,[Parent] ,[Child] ,[DataStore] ,[MemberValid1] ,[Aggregation] ,[Alias] from dbo.HS_Project_Hierarchy where child in ( Select distinct substring (project,1,6) from(select distinct Project from dbo.HS_Hours_Iunion allselect distinct Project from dbo.HS_Hours_II) a))Is there a way where in can create put values in the new table without creating one more staging table as you did in your example. |
 |
|
|
|
|
|
|
|