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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 setting a null

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2009-11-17 : 11:57:38
I have some data that looks like this.


G01 Hardy Rural Families Remote America 224 224 356133
G02 Rural Southern Living Remote America NULL 224 356133
G03 Coal and Crops Remote America NULL 224 356133
G04 Native Americans Remote America NULL NULL NULL

How do i get those nulls to = the values above them?

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-17 : 12:16:42
well the rows are not related...are you saying that they should all default?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-17 : 12:25:11
Well here's a total hack


CREATE TABLE #myTable99(Col1 char(3), Col2 varchar(256), Col3 int, Col4 int, Col5 int)
GO

INSERT INTO #myTable99(Col1, Col2, Col3, Col4, Col5)
SELECT 'G01', 'Hardy Rural Families Remote America', 224, 224, 356133 UNION ALL
SELECT 'G02', 'Rural Southern Living Remote America', NULL, 224, 356133 UNION ALL
SELECT 'G03', 'Coal and Crops Remote America', NULL, 224, 356133 UNION ALL
SELECT 'G04', 'Native Americans Remote America', NULL, NULL, NULL
GO

SELECT a.Col1, a.Col2, b.Col3, b.Col4, b.Col5
FROM #myTable99 a
JOIN (SELECT MIN(Col3) AS Col3, MIN(Col4) AS Col4, MIN(Col5) AS Col5 FROM #myTable99) AS b
ON 1=1
GO

DROP TABLE #myTable99
GO




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -