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 |
|
sross81
Posting Yak Master
228 Posts |
Posted - 2008-05-23 : 11:54:35
|
| Hello,I have a query that creates a list of values. There are labtestcodes that are assigned to different value codes so for example labtest code, value code003277 Height003277 Hgtunt003277 TotVol008300 Height008300 Hgtunt008300 TotVolI want to add a count column to this query that will count the number of value codes in each group so for example 003277 Height 1003277 Hgtunt 2003277 TotVol 3008300 Height 1008300 Hgtunt 2008300 TotVol 3Is there a way to do this in the current query I have?With labtestcheck (labtestcode)as ( select a.labtestcode from EMR_temp_labtest_configupdate a Where Not Exists (Select * From lab_test_add_conf b where b.labtest_key = a.labtestcode))select t.labtestcode,b.zsegcode,b.valuecode,b.valuedesc,b.valuetype,b.units,b.tablename,b.fieldnamefrom EMR_temp_labtest_configupdate ainner join emr_zseg_code_descriptions b on a.zsegcode = b.zsegcodeinner join labtestcheck t on t.labtestcode = a.labtestcode |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-23 : 12:49:24
|
| [code];With labtestcheck (labtestcode)as (select a.labtestcodefrom EMR_temp_labtest_configupdate aWhere Not Exists (Select * From lab_test_add_conf b where b.labtest_key = a.labtestcode))select row_number() over (partition by t.labtestcode order by b.valuecode) as count,t.labtestcode,b.zsegcode,b.valuecode,b.valuedesc,b.valuetype,b.units,b.tablename,b.fieldnamefrom EMR_temp_labtest_configupdate ainner join emr_zseg_code_descriptions b on a.zsegcode = b.zsegcodeinner join labtestcheck t on t.labtestcode = a.labtestcode[/code] |
 |
|
|
sross81
Posting Yak Master
228 Posts |
Posted - 2008-05-23 : 12:58:15
|
Wow thats really cool thanks for that code. I will definitely be saving that one! :)quote: Originally posted by visakh16
;With labtestcheck (labtestcode)as (select a.labtestcodefrom EMR_temp_labtest_configupdate aWhere Not Exists (Select * From lab_test_add_conf b where b.labtest_key = a.labtestcode))select row_number() over (partition by t.labtestcode order by b.valuecode) as count,t.labtestcode,b.zsegcode,b.valuecode,b.valuedesc,b.valuetype,b.units,b.tablename,b.fieldnamefrom EMR_temp_labtest_configupdate ainner join emr_zseg_code_descriptions b on a.zsegcode = b.zsegcodeinner join labtestcheck t on t.labtestcode = a.labtestcode
|
 |
|
|
|
|
|
|
|