| Author |
Topic |
|
dhani
Posting Yak Master
132 Posts |
Posted - 2010-05-11 : 16:07:36
|
| in my sql table i have 8 columns1) please tell me, how can i delete all previous rows, of all first occurance of all null values coulmnsfor example -------------select * from table1col1 col2 col3 col4 col5---- ---- ---- ---- ----AA1 NULL AA3 AA4 AA5AA1 AA2 AA3 AA4 NULLAA1 AA2 NULL NULL NULLAA1 AA2 NULL AA4 AA5AA1 AA2 AA3 AA4 AA5AA1 AA2 AA3 AA4 AA5NULL NULL NULL NULL NULLBB1 BB2 BB3 BB4 BB5BB1 BB2 BB3 BB4 BB5BB1 BB2 BB3 BB4 BB5NULL NULL NULL NULL NULLCC1 CC2 CC3 CC4 CC5CC1 CC2 CC3 CC4 CC5so as of above illustration how can i remove upto 7 th column (because that is first occurance of all null values row)2) in my sql table column (it is actually loads from excel file to sql table through ssis) i have values like this01/1001/27/1002/24/10-0212/24/09 +02/10/10how can i convert any type of value to MMM/YYYYso for example the above ones need to look like asJan/2010Jan/2010Feb/2010Dec/2009please help meThanks in advanceDhani |
|
|
dhani
Posting Yak Master
132 Posts |
Posted - 2010-05-11 : 17:38:51
|
| First One solved with the help of Naomhere it is the solution, may useful to some othersdeclare @t table (col1 char(3),col2 char(3), col3 char(3), col4 char(3), col5 char(3))insert into @t select'AA1', NULL, 'AA3', 'AA4', 'AA5'union all select'AA1', 'AA2', 'AA3', 'AA4', NULLunion all select'AA1', 'AA2', null, null, nullunion all select'AA1', 'AA2', NULL, 'AA4', 'AA5'union all selectNULL, NULL, NULL, NULL, NULLunion all select'BB1', 'BB2', 'BB3', 'BB4', 'BB5'union all select'BB1', 'BB2', 'BB3', 'BB4', 'BB5'union all select'BB1', 'BB2', 'BB3', 'BB4', 'BB5'union all selectNULL, NULL, NULL, NULL, NULLunion all select'CC1', 'CC2', 'CC3', 'CC4', 'CC5'union all select'CC1', 'CC2', 'CC3', 'CC4', 'CC5';with cte as (select *, case when col1 IS NULL and Col2 is NULL and col3 is null and col4 is null and col5 is null then 1 else 10000000000 end * ROW_NUMBER() over (order by (select null)) as Row from @t)delete from cte where Row < (select MIN(Row) * 10000000000 as MinNulls from cte) and Row >=10000000000select * from @t Thanksplease help me in regards to 2nd date column format please................ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-05-12 : 05:59:19
|
| Where do you want to show formatted dates?If you use front end application, do formation thereMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|