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
 required suggestion about table

Author  Topic 

ashishkukreja
Starting Member

16 Posts

Posted - 2007-08-23 : 03:26:42
Hello sir

I just started working in SQL Server so please don't mind when my question is irritating please help me out for this

I have a table having a coloumns

Month-----------------Size----------------------Issue
April-07---------------750----------------------2676
April-07--------------1000--------------------1223
April-07--------------180---------------------3439
April-07--------------90---------------------23562
May-07---------------750----------------------254
May-07--------------375--------------------454
May-07--------------180---------------------454
May-07--------------90---------------------3434

Something like that it is just a example o my table I have data in Thousands

So know what I want to do is I want to add one more coloumn where i want to use if statment something like that

Issue_cases: IIf([size]=1000,[Issue]/9,IIf([size]=750,[Issue]/12,IIf([size]=375,[Issue]/24,IIf([size]=180,[Issue]/48,IIf([size]=90,[Issue]/100)))))

now you please tell me that for this what I have to do I have to create a view or procedure or anything else and how?

Please tell me
I thing I explain my question best
I required your help immediately

Thanks
Ever Smiling
Ashish


You Have to Loss Many Times to Win Single Time

Koji Matsumura
Posting Yak Master

141 Posts

Posted - 2007-08-23 : 05:46:09
SELECT Month, Size, Issue,
NewColumn = 1.0 * Size /
CASE
WHEN Size = 1000 THEN 9
WHEN Size = 750 THEN 12
WHEN Size = 375 THEN 24
:
:
END
Go to Top of Page

ashishkukreja
Starting Member

16 Posts

Posted - 2007-08-23 : 05:56:57
Thanks for your reply

but where I have to put a table name

please reply
Thanks
Ever smiling
Ashish

You Have to Loss Many Times to Win Single Time
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-08-23 : 07:31:09
Did you try at the end of the code?
Read the links in my signature.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

mohit_sme
Starting Member

13 Posts

Posted - 2007-08-23 : 16:51:19
Hi Ashish

I can suggest creating a new computed column for this and put your calculation over there.



Thanks
Mohit Nayyar
http://mohitnayyar.blogspot.com
Go to Top of Page

renu
Starting Member

47 Posts

Posted - 2007-10-04 : 07:28:39
select case c1
when 1000 then c2/9
when 750 then c2/12
when 180 then c2/48
end

from tablename
where c1=1000
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-04 : 07:46:58
[code]Create View V1
as
Select
Month, Size, Issue,
1.0 * Size /
CASE
WHEN Size = 1000 THEN 9
WHEN Size = 750 THEN 12
WHEN Size = 375 THEN 24
...
End As SomeColumn
From SomeTable[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -