473,320 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Stuck with sorting columns

I have the following table (which is an import from another system I
can't mod):-

CREATE TABLE [tbl_wsg_maternity_observations] (
[documentname] [varchar] (40),
[clientguid] [decimal](16, 0) ,
[docguid] [decimal](16, 0) ,
[displayname] [varchar] (80),
[valuetext] [varchar] (255) ,
[valuenum] [float] NULL
) ON [PRIMARY]
GO

Where
documentname is the name of the document
clientguid is the unique identifier for my patient
docguid is the unique id for the document
displayname is the dataitem (e.g. diagnosis)
valuetext is the "answer" (e.g. kidney failure)
valuenum is used instead if the valuetext is an integer (e.g.
number of toes)

I am trying to split/change this table so that I have a different table
per document, with one row per patient occurance with the displaynames
as columns.

I have been using the following but it is slow and for large tables
takes hours (literally) to run:-

SELECT distinct
clientguid,
(SELECT DISTINCT case when t2.[ValueText] is null then
cast(t2.[Valuenum] as varchar(10)) else t2.[ValueText]end FROM
tbl_wsg_maternity_observations t2 WHERE 'How many vessels present in
cord' = t2.[Displayname] AND t1.ClientGUID = t2.ClientGUID AND
t1.docGUID = t2.docGUID) as [How many vessels present in cord],

<SNIP...more identical lines, one per dataitem>

INTO tbl_wsg_baby_delivery_details

FROM
tbl_wsg_maternity_observations t1

WHERE
documentname = 'Mat Baby Delivery Details'
Does anyone have any ideas how to do this faster and preferably more
simply?

Will

Dec 23 '05 #1
4 1142
Ah and one thing... I don't want to get flamed with "you shouldn't be
doing this becasue it overturns X years of Y" . Strangly enough I'd
rather not be doing it but its what the user wants!

Dec 23 '05 #2
Oh and I need it my documentid not patient!!! doh....

Dec 23 '05 #3
(wg******@gmail.com) writes:
Where
documentname is the name of the document
clientguid is the unique identifier for my patient
docguid is the unique id for the document
displayname is the dataitem (e.g. diagnosis)
valuetext is the "answer" (e.g. kidney failure)
valuenum is used instead if the valuetext is an integer (e.g.
number of toes)

I am trying to split/change this table so that I have a different table
per document, with one row per patient occurance with the displaynames
as columns.

I have been using the following but it is slow and for large tables
takes hours (literally) to run:-


I will have to admit that I don't really understand what the result
is to be. Could you post some sample data (preferrably as INSERT
statements), and the desired result?

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Dec 23 '05 #4
On 23 Dec 2005 04:04:26 -0800, wg******@gmail.com wrote:
Ah and one thing... I don't want to get flamed with "you shouldn't be
doing this becasue it overturns X years of Y" .


Hi Will,

I won't flame you, but I will tell you, in all patience, that you should
not do this.

Like Erland, I have trouble understanding what EXACTLY it is that you
want. (I also have trouble understanding WHY you want it, but I just
agreed not to flame you with that <bg>).

But your query LOOKS like some sort of crosstab report. If I'm correct,
then you should indeed look into doing the formatting on the client. It
will be much faster.

If you really have to do it server-side, then check if the following
often-used format for crosstab queries helps you:

USE pubs
go
SELECT pub_id,
SUM(CASE WHEN type = 'business'
THEN ytd_sales ELSE 0 END) AS business,
SUM(CASE WHEN type = 'popular_comp'
THEN ytd_sales ELSE 0 END) AS popular_comp,
SUM(CASE WHEN type = 'psychology'
THEN ytd_sales ELSE 0 END) AS psychology,
SUM(CASE WHEN type = 'trad_cook'
THEN ytd_sales ELSE 0 END) AS trad_cook
FROM titles
GROUP BY pub_id
go
Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Dec 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
4
by: Gareth Gale | last post by:
I'm trying to implement a way of allowing a user to sort a HTML table via Javascript on the client. I've seen lots of samples where single column sorting (asc or desc) is shown, but I'd like nested...
4
by: Richard | last post by:
When i try sorting in the database, it sorts the numbers: 0 1 102 2 304 305 4 etc....
11
by: rkbnair | last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true. When clicking on the column header, the page refreshes. However the sorting is not done. Am I missing anything? I...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
2
by: jediknight | last post by:
Hi, I have a listview which has columns of text and columns of numerical data. I need to be able to sort these columns into ascending/desending order whenever the user clicks on the column...
3
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a question that maybe somebody can help me out. I have a gridview that is bound to a sqltable, and I have created two template columns. I am having problems getting the sorting to work....
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
7
Plater
by: Plater | last post by:
I am having trouble determining when my DataGridView object is sorting (based on a column header click). The idea is, in a large table, sorting the columns takes time, so I show a splash screen....
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.