Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2004, 10:55 AM
Authorized User
 
Join Date: Jun 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do you do this?

Hi,

I have used the cross-tab technique to get a result set back as follows...colume names listed first....

ColName, ColOrders, ColKey, ColEmail
Niall, null, null, null
null, 3, null, null
null, null, 90, null
null, null, null, None

What is the best way to get rid of these nulls and return a single record result set e.g.

ColName, ColOrders, ColKey, ColEmail
Niall, 3, 90, None

It is prefarable that some kind of view\UDF is used.

Thanks
Niall
 
Old April 20th, 2004, 11:37 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

First,
You are trying to concatenate the results from different rows into one set. Your results are different; each line represents an end results.

Is this want you want to do?



 
Old April 20th, 2004, 11:44 AM
Authorized User
 
Join Date: Jun 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Thanks for the reply. Yes, that is what I need to do.

Essenitally I want to transform the rows into columns.
The original table looked like this..

Option, Attribute_Value
---------------------
Name, Niall
Orders, 3
Key, 90
Email, None

So I need to manipulate into..

ColName, ColOrders, ColKey, ColEmail
------------------------------------
Niall, 3, 90, None

Thanks
Niall
 
Old April 20th, 2004, 02:59 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

This is a suggestions and I am sure you will receive others.

Look up information on concatenation on BOOKS ONLINE to start you of.

String Concatenation Operator
The string concatenation operator is the plus sign (+). You can combine, or concatenate, two or more character strings into a single character string. You can also concatenate binary strings. This is an example of concatenation:

SELECT ('abc' + 'def')

Here is the result set:

------
abcdef

(1 row(s) affected)

or
select lastname+ FirstName from employees
where lastname is not null











Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.