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 |
|
ntswakisto
Starting Member
33 Posts |
Posted - 2009-07-10 : 04:46:38
|
| Anyone that can help with the following query...I need to show week day on the same column with date column...Query:Select convert(varchar(10),JMPSH.CreateDate,111) as PackingSlipDate,Datename(Weekday,convert(varchar(10),JMPSH.CreateDate,111)) as [Week Day].From Cet.dbo.JMPackSlipHeader as JMPSHResultsPackagingslipDate Week_Day2009/06/01 Monday2009/06/02 Tuesday2009/06/03 Wednesday2009/06/04 Thursday2009/06/05 FridayI need them to look like this as one column,PackagingslipDate 2009/06/01(Monday)2009/06/02(Tuesday)2009/06/03(Wednesday)2009/06/04(Thursday)2009/06/05(Friday) |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-10 : 04:48:37
|
[code]Select convert(varchar(10),JMPSH.CreateDate,111) + '(' Datename(Weekday, JMPSH.CreateDate)) + ')' as PackagingslipDate From Cet.dbo.JMPackSlipHeader as JMPSH[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ntswakisto
Starting Member
33 Posts |
Posted - 2009-07-10 : 05:34:06
|
quote: Originally posted by khtan
Select convert(varchar(10),JMPSH.CreateDate,111) + '(' Datename(Weekday, JMPSH.CreateDate)) + ')' as PackagingslipDate From Cet.dbo.JMPackSlipHeader as JMPSH KH[spoiler]Time is always against us[/spoiler]thanks khtanit workedi tried it like this....just added the convert statement on the weekday part....SELECT convert(varchar(10),JMPSH.CreateDate,111) + ' ' + '(' + Datename(Weekday,convert(varchar(10),JMPSH.CreateDate,111))+ ')' as PackingSlipDateFROM Cetus.dbo.JMPackSlipHeader as JMPSHresults2009/06/03 (Wednesday)2009/06/05 (Friday)2009/06/01 (Monday)2009/06/12 (Friday)2009/06/02 (Tuesday)2009/06/12 (Friday)
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-10 : 05:53:00
|
you don't need to convert to varchar for the datename() function. It accepts datetime KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ntswakisto
Starting Member
33 Posts |
Posted - 2009-07-10 : 06:11:50
|
quote: Originally posted by khtan you don't need to convert to varchar for the datename() function. It accepts datetime KH[spoiler]Time is always against us[/spoiler]
thanks for your...khtan |
 |
|
|
ntswakisto
Starting Member
33 Posts |
Posted - 2009-07-10 : 08:18:17
|
quote: Originally posted by khtan you don't need to convert to varchar for the datename() function. It accepts datetime KH[spoiler]Time is always against us[/spoiler]Hi KH Any idea how to add column totals in a Pivot query table....here is the queryI need to add column total to my pivot query and appear as last row in the table results.....Select PackingSlipDate, [Bag],[BoxAA],[EmptyStand],[FullStand],[Other]From (SELECT HHCT.ContainerType,convert(varchar(10),JMPSH.CreateDate,120) as PackingSlipDate,Count(JMPSH.pkPackingSlipID) AS TotalFROM Cetus.dbo.JMPackSlipHeader as JMPSHINNER JOIN Cetus.dbo.HHContainerType as HHCT ON JMPSH.fkContainerType = HHCT.pkContainerTypeIDINNER JOIN usCustomers.dbo.Customers As C ON JMPSH.CustomerID = C.CustomerIDWhere JMPSH.CreateDate between '2009-05-01' and '2009-05-31'and C.MerchPreference = 'Y'GROUP BY HHCT.ContainerType,convert(varchar(10),JMPSH.CreateDate,120)) AS SPIVOT(Sum(Total)FOR ContainerType IN ([Bag],[BoxAA],EmptyStand],[FullStand],[Other]) AS PORDER BY PackingSlipDateI need results to look like this:Packaging Date Bag BoxAA EmptyStand FullStand Other 2009/05/04 4 38 8 4 NULL 2009/05/05 17 175 10 NULL NULL 2009/05/06 15 442 4 16 NULL 2009/05/07 6 561 10 5 NULL 2009/05/08 8 372 12 NULL NULL 2009/05/11 4 142 3 1 NULL 2009/05/12 16 151 21 11 NULL Total 70 1881 68 37 0
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-10 : 08:40:42
|
use CTE;with cte (PackingSlipDate, [Bag],[BoxAA],[EmptyStand],[FullStand],[Other])as( < your existing query here >)select PackingSlipDate, [Bag],[BoxAA],[EmptyStand],[FullStand],[Other]from cteunion allselect 'Total', sum([Bag]), sum([BoxAA]), sum([EmptyStand]), sum([FullStand]), sum([Other])from cte KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ntswakisto
Starting Member
33 Posts |
Posted - 2009-07-13 : 04:28:07
|
quote: Originally posted by khtan use CTE;with cte (PackingSlipDate, [Bag],[BoxAA],[EmptyStand],[FullStand],[Other])as( < your existing query here >)select PackingSlipDate, [Bag],[BoxAA],[EmptyStand],[FullStand],[Other]from cteunion allselect 'Total', sum([Bag]), sum([BoxAA]), sum([EmptyStand]), sum([FullStand]), sum([Other])from cte KH[spoiler]Time is always against us[/spoiler]Hi KHI am still working on getting the column totals...not really good with CTE....
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-13 : 04:37:09
|
do you have problem with your query ? What's the problem ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ntswakisto
Starting Member
33 Posts |
Posted - 2009-07-13 : 05:00:20
|
quote: Originally posted by khtan do you have problem with your query ? What's the problem ? KH[spoiler]Time is always against us[/spoiler]I am not sure how to use CTE with Pivot query table...where to add the CTE query to get column totals.
|
 |
|
|
|
|
|
|
|