Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have table in sql
samiksha    sharad  sac
       0    10  0
       1    0   0


I want only 1 row instead of 2 rows, i want to hide 0 .

thanks in advance for query.
Posted
Updated 21-Nov-13 22:00pm
v3

SQL
select * ,row_number() over(order by sac asc) as rowid into #temp from sql table

select * from #temp where rowid not in(1)

now try it
 
Share this answer
 
v3
Comments
Master Vinu 22-Nov-13 3:57am    
Thx Rahul, but its not resolved my issue , it shows null value instead of 0, but rows are 2 only,
i wan 1 row only.
Rahul_Pandit 22-Nov-13 4:09am    
try updated solution now
Master Vinu 22-Nov-13 4:11am    
thx rahul. but,

actually i wan 1 rows only with record like 1 10 0 .

hope y get my prob?
Rahul_Pandit 22-Nov-13 4:13am    
you want one row if other values are zero
Master Vinu 22-Nov-13 4:13am    
yes
If you want only 1. row
SQL
SELECT samiksha, sharad, sac	
FROM TableName
WHERE sharad <> 0 AND sac <> 0

or
if you want only 2. row
SQL
SELECT samiksha, sharad, sac	
FROM TableName
WHERE samiksha <> 0


[EDIT]

SQL
DECLARE @tmp TABLE (samiksha INT, sharad INT, sac INT)

INSERT INTO @tmp (samiksha,sharad,sac)
    VALUES(0, 10, 0), (1, 0, 0)


SELECT samiksha, sharad, sac
FROM @tmp
WHERE sharad <> 0 AND sac <> 0

SELECT samiksha, sharad, sac
FROM @tmp
WHERE samiksha <> 0

SELECT SUM(samiksha) AS samiksha, SUM(sharad) AS sharad, SUM(sac) AS sac
FROM @tmp


Returned values:
1. query
(none)

2. query
1	0	0

3. query
1	10	0

[/EDIT]
 
Share this answer
 
v2
Comments
Master Vinu 22-Nov-13 4:39am    
maciej thx but not working
Maciej Los 22-Nov-13 5:13am    
What's not working? It is not informative at all. Do you have any error message?
Does sharad and sac are numeric fields or string? If string, add ' before and after zero.
Example:
WHERE sharad<>'0'
Master Vinu 22-Nov-13 5:35am    
its numeric field
Maciej Los 22-Nov-13 5:53am    
Also, what's wrong?
See my answer after update.
update all zero to null and try this

select coalesce(samiksha,sharad,sac) as samiksha , coalesce(samiksha,sharad,sac) as sharad ,coalesce(samiksha,sharad,sac) as sac from table

accept it if it works for you.
 
Share this answer
 
Comments
Master Vinu 22-Nov-13 4:38am    
no rahul its not working
XML
select j.`samiksha` ,j1.`sharad`,j2.`sac`  AS sac
FROM tablename j
LEFT JOIN tablename j1 ON j1.`sharad` <> 0
LEFT JOIN tablename j2  ON j2.`sac` <> 0
WHERE j.samiksha <> 0;


just use join on that table...u will get result what u want.

This is working ............try it reply me.....
 
Share this answer
 
v2
Comments
[no name] 23-Nov-13 0:27am    
hi vinayak
Its working ,why you are not trying this ? IF it not works reply me ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900