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 |
|
jhon11
Starting Member
42 Posts |
Posted - 2007-12-14 : 12:44:44
|
| Hi,I have a table in which i have two colums say discription and counts.the table has 10 rows.This table is created by extracting data from other table means its not a table that exist in system.Now in my last row i want discription as '%mailed' and count as row1/row2can u tell me how to do that? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-12-14 : 14:07:24
|
| Where's the query and a data example of your problem?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
jhon11
Starting Member
42 Posts |
Posted - 2007-12-14 : 14:12:27
|
| declare @intLoadInstanceId intdeclare @productcode intselect @intLoadInstanceId='24'select @productcode='2'create table #mailingCounts( Decription varchar(100) ,Counts smallint)--Count of Total patientsInsert into #mailingCountsselect 'Count of Total Patients',count(distinct patientid) from dbo.HCOFixedwhere intLoadInstanceId=@intLoadInstanceIdand productcode=@productcode--Count of patients in mailingInsert into #mailingCountsselect 'Count of Patients in Mailing',count(distinct patientid)from mailingtablewhere intLoadInstanceId=@intLoadInstanceIdand productcode=@productcode--Count of packets mailedInsert into #mailingCountsselect 'Count of Packets mailed',count(*)from mailingtablewhere intLoadInstanceId=@intLoadInstanceIdand productcode=@productcode--This section shows the number of packets mailed to each type of doctorInsert into #mailingCountsselect 'Count of Packets Mailed to CMHC ',count(*)from dbo.ProviderMailing pinner join MailingTable m on m.intLoadInstanceID=p.intLoadInstanceIDand m.productcode=p.productcodeand m.mailto=p.PrescriberIDwhere p.intLoadInstanceid = @intLoadInstanceidand p.type ='Age'and p.productcode=@productcodeInsert into #mailingCountsselect 'Count of Packets Mailed to Physician',count(*)from dbo.ProviderMailing pinner join MailingTable m on m.intLoadInstanceID=p.intLoadInstanceIDand m.productcode=p.productcodeand m.mailto=p.PrescriberIDwhere p.intLoadInstanceid = @intLoadInstanceidand p.type ='Gen'and p.productcode=@productcodeInsert into #mailingCountsselect 'Count of Packets Mailed to Psychiatrist',count(*) from dbo.ProviderMailing pinner join MailingTable m on m.intLoadInstanceID=p.intLoadInstanceIDand m.productcode=p.productcodeand m.mailto=p.PrescriberIDwhere p.intLoadInstanceid = @intLoadInstanceidand p.type ='Psychiatrist'and p.productcode=@productcodeInsert into #mailingCountsselect 'Count of Packets Mailed to Spec ',count(*)from dbo.ProviderMailing pinner join MailingTable m on m.intLoadInstanceID=p.intLoadInstanceIDand m.productcode=p.productcodeand m.mailto=p.PrescriberIDwhere p.intLoadInstanceid = @intLoadInstanceidand p.type ='Spec'and p.productcode=@productcode--final outputselect * from #mailingCounts |
 |
|
|
|
|
|