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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 IF THEN command in sql qury

Author  Topic 

InF3sted
Starting Member

18 Posts

Posted - 2008-09-11 : 04:53:13
ok,i have a problem i don't know the solution,i need to do this:

select ekstenzija, count(*)
from dbo.contentcache
where command = 'vc'
group by ekstenzija

when i try this i only see extension 3gp with number 46,but other field is blank,and the number is ok,i dont'how to show name in that other field,any solution???

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-09-11 : 04:56:11
Which other field is blank? Please provide table structure, sample data and expected out put.

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-11 : 04:56:34
is this what you want ?
select ekstenzija, count(*) as [Count]
from dbo.contentcache
where command = 'vc'
group by ekstenzija



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-11 : 04:58:27
or this ?
select case when ekstenzija = '' 
then 'Something'
else ekstenzija
end as [ekstenzija],
[Count]
from
(
select ekstenzija, count(*) as [Count]
from dbo.contentcache
where command = 'vc'
group by ekstenzija
) a



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-11 : 05:04:46
ok
goes like this i have a table named ContentCache and from that table i need to show just two counted rows"how many 3gp and how many GIF
but i don't have a GIF name,when i try with that command u writed or mine,i got two rows one is 3gp counted some number but other one does not have name,just blank file(insted of that blank field i need to write GIF,but not for always ,just in that momment needs to be GIF,and thats it?
Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-11 : 05:06:37
THANK U SO MUCH KHTAN this second solution solved my problem,THANKS A LOT
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-11 : 05:07:29
is it blank or NULL
maybe like this ?

select case when ekstenzija = '' or ekstenzija is null
then 'GIF'
else ekstenzija
end as [ekstenzija],
[Count]
from
(
select ekstenzija, count(*) as [Count]
from dbo.contentcache
where command = 'vc'
group by ekstenzija
) a



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-11 : 05:18:09
thats not what i need-ed to to :(
it seems that i don't need to put GIF instead of blank field,i need to leave it blank but to make third row for the GIF that will say when countin 0???

IM SORRY FOR TROUBLING U GUYS,I MISSUNDERSTOUD what i need to do
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-11 : 05:19:10
[code]
select ekstenzija, count(*) as [Count]
from dbo.contentcache
where command = 'vc'
group by ekstenzija

union all

select 'GIF', 0
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-11 : 05:25:05
ok that's a solution i need,it work,THANK YOU
Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-11 : 05:42:08
hell,again it's not a solution,my teacher says that i can put anything instead of this 0,he wants GIF to be there but select need's to count it i put 0,that i can't put 0 it needs to automaically counts and put 0???
Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-11 : 06:09:16
he said to me that i must use if and then ans SUM
Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-11 : 08:10:55
so no solutions?????
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-11 : 08:15:41
what do you want to count for GIF ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-11 : 10:12:07
wanna use GIf but it isn't in table,i want to show gif and when it counts need to be 0,but not tlike that select ekstenzija, count(*) as [Count]
from dbo.contentcache
where command = 'vc'
group by ekstenzija

union all

select 'GIF', 0

i need to count them even if they are not there with something using IF THEN AND SUM?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-09-11 : 10:23:17
Sorry, don't understand what your teacher wants. Good luck.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-17 : 07:32:04
it's me again,i didn't found any soulution for this,can u look at it again,

select ekstenzija, count(*)
from dbo.contentcache
where command = 'vc'
group by ekstenzija


let's say i have this SELECT command,and it is ok,but i need to coun how many blank field are in a table and to adda GIF in a table and count that GIF,,,but i need to use CASE or if and then in it????
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-17 : 07:48:21
quote:
Originally posted by InF3sted

it's me again,i didn't found any soulution for this,can u look at it again,

select ekstenzija, count(*)
from dbo.contentcache
where command = 'vc'
group by ekstenzija


let's say i have this SELECT command,and it is ok,but i need to coun how many blank field are in a table and to adda GIF in a table and count that GIF,,,but i need to use CASE or if and then in it????


GIF? what GIF? you mean the value 'GIF'?
Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-17 : 07:50:38
yes value GIF sorry i forgot to write
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-17 : 08:03:13
quote:
Originally posted by InF3sted

yes value GIF sorry i forgot to write


you want to add GIF value for each blank and count it?
Go to Top of Page

InF3sted
Starting Member

18 Posts

Posted - 2008-09-17 : 08:06:39
no GIF isn't in table,i need to create row GIF and to count it(the result will be 0)and i need to coun blank fields in table,it needs to be blank no need to write something instead it..that's it
just i need to use CASE and IF and THEN for that,any solution????
Go to Top of Page
    Next Page

- Advertisement -