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 |
|
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_namehere is my sample data :Table : ec_resourceresource_id resource_name24 BTRPOD10427 BTRPOD20328 BTRPOD20435 STRUTTable resource_poolresource_id resource_pool_name24 POD127 POD228 POD2Expected output host_jobdata:HOST_NAME RESOURCE_POOL_NAME RESOURCE_NAMEPod1 POD1 NULLPod2 pod2 NULLBTRPOD104 NULL BTRPOD104BTRPOD203 NULL BTRPOD203STRUT 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. |
 |
|
|
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_NAMEPod1 POD1 NULLPod2 pod2 NULLBTRPOD104 NULL BTRPOD104BTRPOD203 NULL BTRPOD203STRUT NULL STRUTquote: 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.
|
 |
|
|
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. |
 |
|
|
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 thatBTRPOD204 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_NAMEPod1 POD1 NULLPod2 pod2 NULLBTRPOD104 NULL BTRPOD104BTRPOD203 NULL BTRPOD203STRUT NULL STRUTBTRPOD204 NULL BTRPOD204 quote: Originally posted by pk_bohra why u don't want BTRPOD204 in your output.
|
 |
|
|
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_resourceSelect 24, 'BTRPOD104' unionSelect 27, 'BTRPOD203' unionSelect 28 , 'BTRPOD204' unionSelect 35 , 'STRUT'Insert into @resource_poolSelect 24,'POD1' unionSelect 27,'POD2' unionSelect 28,'POD2' Select H.resource_pool_name as HostName,H.resource_pool_name as RESOURCE_POOL_NAME,Null as RESOURCE_NAMEFrom @resource_pool HUnionSelect H.resource_name as HostName,Null as RESOURCE_POOL_NAME,resource_name as RESOURCE_NAMEFrom @ec_resource H |
 |
|
|
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_resourceSelect 24, 'BTRPOD104' unionSelect 27, 'BTRPOD203' unionSelect 28 , 'BTRPOD204' unionSelect 35 , 'STRUT'Insert into @resource_poolSelect 24,'POD1' unionSelect 27,'POD2' unionSelect 28,'POD2' Select H.resource_pool_name as HostName,H.resource_pool_name as RESOURCE_POOL_NAME,Null as RESOURCE_NAMEFrom @resource_pool HUnionSelect H.resource_name as HostName,Null as RESOURCE_POOL_NAME,resource_name as RESOURCE_NAMEFrom @ec_resource H
|
 |
|
|
|
|
|
|
|