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
 Separating one column data into two columns

Author  Topic 

rds207
Posting Yak Master

198 Posts

Posted - 2010-04-09 : 12:36:36
Hi

i have a column in my table called host_name which is a combination of resource name and resource pool names.i need to have another 2 column where i can update resource_name and resource_pool_name separately from Host_name

here is my sample data :

Table : ec_resource

resource_id resource_name

24 BTRPOD104
27 BTRPOD203
28 BTRPOD204
35 STRUT

Table resource_pool


resource_id resource_pool_name
24 POD1
27 POD2
28 POD2

Expected output host_jobdata:

HOST_NAME RESOURCE_POOL_NAME RESOURCE_NAME
Pod1 POD1 NULL
Pod2 pod2 NULL
BTRPOD104 NULL BTRPOD104
BTRPOD203 NULL BTRPOD203
STRUT NULL STRUT


PLEASE HELP!

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-04-09 : 12:54:40
Can you please check your sample data. The input doesn't appear to correspond to the desired output. eg, where did BLDBAT05 come from?

------------------------------------------------------------------------------------
Any and all code contained within this post comes with a 100% money back guarantee.
Go to Top of Page

rds207
Posting Yak Master

198 Posts

Posted - 2010-04-09 : 13:08:15
SORRY , Please check now

here is the expected output:

Expected output host_jobdata:

HOST_NAME RESOURCE_POOL_NAME RESOURCE_NAME
Pod1 POD1 NULL
Pod2 pod2 NULL
BTRPOD104 NULL BTRPOD104
BTRPOD203 NULL BTRPOD203
STRUT NULL STRUT


quote:
Originally posted by DBA in the making

Can you please check your sample data. The input doesn't appear to correspond to the desired output. eg, where did BLDBAT05 come from?

------------------------------------------------------------------------------------
Any and all code contained within this post comes with a 100% money back guarantee.

Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-04-09 : 13:28:15
why u don't want BTRPOD204 in your output.

Go to Top of Page

rds207
Posting Yak Master

198 Posts

Posted - 2010-04-09 : 13:51:09
its not like i dont want it , i have output column host_name which is a combination of resourcenames and resource pool names , its just that
BTRPOD204 is not in the output of host name i selected, so thats the reason i did not give it in the output ,

i will change the output to avoid confusion ,

HOST_NAME RESOURCE_POOL_NAME RESOURCE_NAME
Pod1 POD1 NULL
Pod2 pod2 NULL
BTRPOD104 NULL BTRPOD104
BTRPOD203 NULL BTRPOD203
STRUT NULL STRUT
BTRPOD204 NULL BTRPOD204



quote:
Originally posted by pk_bohra

why u don't want BTRPOD204 in your output.



Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-04-09 : 13:54:01
Try this:

Declare @ec_resource Table
(resource_id int,
resource_name varchar(50)
)


Declare @resource_pool Table
(resource_id int,
resource_pool_name varchar(50)
)

Insert into @ec_resource
Select 24, 'BTRPOD104' union
Select 27, 'BTRPOD203' union
Select 28 , 'BTRPOD204' union
Select 35 , 'STRUT'


Insert into @resource_pool
Select 24,'POD1' union
Select 27,'POD2' union
Select 28,'POD2'


Select H.resource_pool_name as HostName,H.resource_pool_name as RESOURCE_POOL_NAME,Null as RESOURCE_NAME
From @resource_pool H
Union
Select H.resource_name as HostName,Null as RESOURCE_POOL_NAME,resource_name as RESOURCE_NAME
From @ec_resource H
Go to Top of Page

rds207
Posting Yak Master

198 Posts

Posted - 2010-04-09 : 18:03:13
quote:
Originally posted by rds207

There are almost 20 columns in host_jobdata table , with some millions of records , and from source table i get the host_name with combination of resourcenames and resource_pool_names ,
so i need to separate THAT hostname columns into two columns, resource names and resourcepoolnames ,
depending upon hostnames , if the hostname for that particular record falls into resourcepoolnames , then update resourcepoolcolumn with the same hostname and if hostname for that particular record falls in resourcenames them update resourcename with hostname else update with null.......

Please help ,

quote:
Originally posted by pk_bohra

Try this:

Declare @ec_resource Table
(resource_id int,
resource_name varchar(50)
)


Declare @resource_pool Table
(resource_id int,
resource_pool_name varchar(50)
)

Insert into @ec_resource
Select 24, 'BTRPOD104' union
Select 27, 'BTRPOD203' union
Select 28 , 'BTRPOD204' union
Select 35 , 'STRUT'


Insert into @resource_pool
Select 24,'POD1' union
Select 27,'POD2' union
Select 28,'POD2'


Select H.resource_pool_name as HostName,H.resource_pool_name as RESOURCE_POOL_NAME,Null as RESOURCE_NAME
From @resource_pool H
Union
Select H.resource_name as HostName,Null as RESOURCE_POOL_NAME,resource_name as RESOURCE_NAME
From @ec_resource H




Go to Top of Page
   

- Advertisement -