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 2005 Forums
 Transact-SQL (2005)
 computed column formula

Author  Topic 

raokikun
Starting Member

8 Posts

Posted - 2011-08-28 : 01:02:02
i got two columns in mysql 2005

Grade and Remarks

i need to do is.. when i input integers in grade column

1,1.25,1.50,1.75,2,2.25,2.50,2.75,3

then Remarks will show PASSED

and when Grade is 4 up

remarks will show FAILED

(OPTIONAL)----------------------
if Grade is null -
then Remarks will show UNKnOWN -
--------------------------------

this is my code but it doesnt works on sql computed column formula

IIF(Grade >=4, 'Failed', IIF(Grade IN (1,1.25,1.50,1.75,2,2.25,2.50,2.75,3), 'PASSED','UNKNOWN'))



can anyone revise my code into.. sql formula code?? thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-28 : 01:51:35
it should be like

CREATE TABLE ...
.... othercolumns,
Grade ....,
Remarks AS CASE WHEN Grade IS NULL THEN 'UNKNOWN'
WHEN Grade <4 THEN 'PASSED'
ELSE 'FAILED'
END
)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

raokikun
Starting Member

8 Posts

Posted - 2011-08-28 : 03:00:59
thank you sir i will try it asap!i wish it works!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-28 : 03:13:00
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

raokikun
Starting Member

8 Posts

Posted - 2011-08-28 : 04:02:54
the computer column remarks doesnt works?

i got no problem on creating the database and table
no problem on connecting it to the visual basic

but when executing

when i input grades
nothing happens to the remarks computed column

how can i do that.. help sir

i really need this for my thesis.. in order to graduate
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-28 : 06:25:29
Can you show your create script?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

raokikun
Starting Member

8 Posts

Posted - 2011-08-28 : 22:17:58
create database ccs

create table student
(
P_Key int IDENTITY,
Student_Number varchar(50) NULL,
Grade decimal(10) NULL,
PRIMARY KEY (P_Key),
Remarks AS CASE WHEN Grade IS NULL THEN 'UNKNOWN'
WHEN Grade <4 THEN 'PASSED'
ELSE 'FAILED'
END
)


please sir i need this in order to graduate..

i also tried coding if/else in the expression property of the dataset..

it also makes it computed column but its the same problem

it doesnt work even with no errors or exceptions
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-29 : 00:39:34
its working for me. see below:-


drop table student

create table student
(
P_Key int IDENTITY,
Student_Number varchar(50) NULL,
Grade decimal(10) NULL,
PRIMARY KEY (P_Key),
Remarks AS CASE WHEN Grade IS NULL THEN 'UNKNOWN'
WHEN Grade <4 THEN 'PASSED'
ELSE 'FAILED'
END
)


insert into student (Student_Number,Grade)
select 'abnm',1 union all
select 'fdw',null union all
select 'aFS',2 union all
select 'zxvc',7 union all
select 'zV',5 union all
select 'abnzvxzxvm',3

select * from student

output
------------------------------------
P_Key Student_Number Grade Remarks
----------- ----------------------------- ----------------- -------
1 abnm 1 PASSED
2 fdw NULL UNKNOWN
3 aFS 2 PASSED
4 zxvc 7 FAILED
5 zV 5 FAILED
6 abnzvxzxvm 3 PASSED



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-29 : 00:40:42
one more question. why you've declared grade as decimal(10). if you dont want to store decimal part why not make it int instead?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

raokikun
Starting Member

8 Posts

Posted - 2011-08-29 : 01:03:29
grade is decimal sir.
because. ahm our system must read 1, 1.25, 1.50, 1.75 etc. its for our school

------sir would you mind testing it in visual basic. by adding the database and table by data sources.. thats where i get the problem

sir may i ask a question..
what is the purpose of union all?

have you tried it in vb.net? and is it working?
i must not add records or grades using sql

NOTE:
i must add records using vb.net in a datagrid view

ill give it a try again, hope this works for now
im running out of time for our thesis..im the only one making in our group because my groupmates doesnt know anything about coding..

THANK THANK YOU VERY MUCH! ill give it a try now asap :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-29 : 01:15:14
quote:
Originally posted by raokikun

grade is decimal sir.
because. ahm our system must read 1, 1.25, 1.50, 1.75 etc. its for our school
then make sure you give a scale value too ie like decimal(10,2) else it will default to 0 and you cant store decimal
sir may i ask a question..
what is the purpose of union all?
union all is used for merging resultset from different queries see example usage in MSDN or books online
have you tried it in vb.net? and is it working?
i must not add records or grades using sql

NOTE:
i must add records using vb.net in a datagrid view

ill give it a try again, hope this works for now
im running out of time for our thesis..im the only one making in our group because my groupmates doesnt know anything about coding..
then it might be problem in calling query from VB app. I'm not an expert on VB so you can post it in VB forum to get more help
THANK THANK YOU VERY MUCH! ill give it a try now asap :)



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

raokikun
Starting Member

8 Posts

Posted - 2011-08-29 : 01:27:17
thank you very much sir! i learned a lot from you.

good day! and god bless
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-29 : 01:29:10
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -