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
 General SQL Server Forums
 New to SQL Server Programming
 Help on query

Author  Topic 

SP273
Starting Member

14 Posts

Posted - 2011-02-26 : 10:20:22
Hello all,

I have the following query:

Insert Into dbo.HS_Projects_Hierarchy
([LoadID]
,[Parent]
,[Child]
,[DataStorage]
,[MemberValidForPlan1]
,[Plan1Aggregation]
,[Alias=Default])
( select [LoadID]
,--[Parent]
Case when substring(Child,1,2) in ('D0','D1','D2','D3','D4','D5','D5','D6','D7','D8','D9') Then 'D Projects' Else 'IProjects' END AS Parent
,[Child]
,[DataStorage]
,[MemberValidForPlan1]
,[Plan1Aggregation]
,[Alias=Default]

from Convert_Projects where Child in
(
select SUBSTRING (Child,1,6)FROM Convert_Projects
)

)

What I am trying is to insert all the values from Covert_Projects to dbo.HS_Projects_Hierarchy but when i bring the values over I just want to bring first 6 characters in child column of Convert_Projects table(Original lenghth is 16)

Right now if I run the query it returns me 0 rows as its looking up for all the projects of string lengh 6 & not performing any action where in it can grab the first 6 charaters.

How can i modify the query to keep all the columns as it is & juss copy first 6 characters of child into the new table.

Any help would be appreciated.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-26 : 10:25:23
like this ?


Insert Into dbo.HS_Projects_Hierarchy
([LoadID]
,[Parent]
,[Child]
,[DataStorage]
,[MemberValidForPlan1]
,[Plan1Aggregation]
,[Alias=Default])
( select [LoadID]
,--[Parent]
Case when substring(Child,1,2) in ('D0','D1','D2','D3','D4','D5','D5','D6','D7','D8','D9') Then 'D Projects' Else 'IProjects' END AS Parent
,LEFT([Child],6)
,[DataStorage]
,[MemberValidForPlan1]
,[Plan1Aggregation]
,[Alias=Default]
from Convert_Projects



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SP273
Starting Member

14 Posts

Posted - 2011-02-26 : 12:39:27
Thanks that was helpul
Go to Top of Page
   

- Advertisement -