Can someone help me parsing this ms-access PIVOT sql-statement to a
ms-sql-server sql-statement?
Many thanks in advance
TRANSFORM Count(KlantenSt ops.id) AS AantalVanid
SELECT KlantenStops.Ui tvoerder, KlantenStops.Kl ant
FROM KlantenStops
GROUP BY KlantenStops.Ui tvoerder, KlantenStops.Kl ant
PIVOT DatePart("m",le verdatum,1,0) In
("1","2","3","4 ","5","6","7"," 8","9","10","11 ","12"); 3 6295
On Wed, 18 Jan 2006 19:49:49 +0100, Gert v O wrote: Can someone help me parsing this ms-access PIVOT sql-statement to a ms-sql-server sql-statement? Many thanks in advance
TRANSFORM Count(KlantenSt ops.id) AS AantalVanid SELECT KlantenStops.Ui tvoerder, KlantenStops.Kl ant FROM KlantenStops GROUP BY KlantenStops.Ui tvoerder, KlantenStops.Kl ant PIVOT DatePart("m",le verdatum,1,0) In ("1","2","3"," 4","5","6","7", "8","9","10","1 1","12");
Hi Gert,
I'm not exactly sure how the Access PIVOT syntax works (including table
structure, sample data and expected results would have been a good idea;
check www.aspfaq.com/2006 for the best format to supply this info), but
the query below will do what I think the Access format does:
SELECT Uitvoerder, Klant,
COUNT(CASE WHEN DATEPART(month, leverdatum) = 1 THEN 'TelMe'
END) AS Januari,
COUNT(CASE WHEN DATEPART(month, leverdatum) = 2 THEN 'TelMe'
END) AS Februari,
.....,
COUNT(CASE WHEN DATEPART(month, leverdatum) = 12 THEN 'TelMe'
END) AS December
FROM KlantenStops
GROUP BY Uitvoerder, Klant
If you're using SQL Server 2005, you can also use the new PIVOT syntax.
You'll have to check Books Online for the details, though, as I haven't
had a chance to play with the new syntax yet.
--
Hugo Kornelis, SQL Server MVP
Hugo Kornelis wrote: On Wed, 18 Jan 2006 19:49:49 +0100, Gert v O wrote:
Can someone help me parsing this ms-access PIVOT sql-statement to a ms-sql-server sql-statement? Many thanks in advance
TRANSFORM Count(KlantenSt ops.id) AS AantalVanid SELECT KlantenStops.Ui tvoerder, KlantenStops.Kl ant FROM KlantenStops GROUP BY KlantenStops.Ui tvoerder, KlantenStops.Kl ant PIVOT DatePart("m",le verdatum,1,0) In ("1","2","3","4 ","5","6","7"," 8","9","10","11 ","12");
Hi Gert,
I'm not exactly sure how the Access PIVOT syntax works (including table structure, sample data and expected results would have been a good idea; check www.aspfaq.com/2006 for the best format to supply this info), but the query below will do what I think the Access format does:
SELECT Uitvoerder, Klant, COUNT(CASE WHEN DATEPART(month, leverdatum) = 1 THEN 'TelMe' END) AS Januari, COUNT(CASE WHEN DATEPART(month, leverdatum) = 2 THEN 'TelMe' END) AS Februari, ....., COUNT(CASE WHEN DATEPART(month, leverdatum) = 12 THEN 'TelMe' END) AS December FROM KlantenStops GROUP BY Uitvoerder, Klant
If you're using SQL Server 2005, you can also use the new PIVOT syntax. You'll have to check Books Online for the details, though, as I haven't had a chance to play with the new syntax yet.
Thanx Hugo
I have a blog post on using dynamic SQL to pivot when you don't know how many columns there will be it's here http://www.daymap.net/blog This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike Daniel |
last post by:
I am attempting to use document.write(pageVar) that displays a new html page
within a pop-up window and the popup is failing. Also note that pageVar is
a complete HTML page containing other java scripts.
Being a javascript newbie and after significant testing, I suspect that the
document.write fails after finding a </script> within pageVar.
Does a trick exist that enables one to slightly alter pageVar whereby
enabling...
|
by: slim |
last post by:
hi again all,
i am still working on the website as mentioned in earlier threads and
have hit another snag...
http://awash.demon.co.uk/index.php
http://awash.demon.co.uk/vd.css
the php is pulling a name and placing it under the thumbnail (the text is
|
by: Bob |
last post by:
Help wanted
Does anyone know of any books out there that addresses the problems of
marketing an Access Database program with front/back end arrangement.
What I am looking for is a book that addresses the different angles
and ways of doing the following:
1. What is the best way to deliver Ftp, CD,
|
by: Pratik Parikh |
last post by:
Hi eveyone,
Hi EveryOne,
I am having a real problem, which i am unable to resolve.
The problem is that i am tring to convert the datset using
XmlDataDocument, following is the code. My Problem is that
the while assigning the InnerXml to string variable
stream. it add escape character to my xml stream. after
the code is the example...of xml output. A help will be
|
by: Bobstar |
last post by:
Hello.
In the good ol'ASP-days I allways handled all request vars within a class. I
want to do the same in ASP.NET. It can be done smart and maybe not so smart -
and I need help for the first part :-)
I've the following:
public class UserSettings
{
| |
by: Klaus Herzberg |
last post by:
Hi,
I come from the "dark side" php/mysql and there often problems with
character sets (utf-8, latin...) and storing data in datebase.
Exists in the world of dot.net and ms-sql-server similiar problems?
To precise: I have to store xml-data in database. Maybe its better to
encode (like base64) the strings?
Perhaps there are some links to read?
|
by: rfox |
last post by:
My company's looking to hire a very well-qualified web developer. Is
there a more appropriate place to post a help-wanted ad than this
forum?
|
by: thecolonel |
last post by:
In Oracle, as I'm using the GUI to create tables, I can also look at older tables and the SQL it would take to create those tables again. Does MSSQL 2005 have this same feature anywhere in the Management Studio? I ask because I need to create a large number of tables that already exist in this database in a different place, so it would be nice if I could just view the script it would take to create these tables rather than having to write all...
|
by: Adem |
last post by:
Projects looking for Developer
Help Wanted
- 174 Developer
- 9 Project Manager
- 1 Unix Admin
- 47 Doc Writer
- 29 Tester
- 4 Support Manager
- 27 Graphic/Other Designer
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |