Author |
Topic |
raokikun
Starting Member
8 Posts |
Posted - 2011-08-28 : 01:02:02
|
i got two columns in mysql 2005Grade and Remarksi need to do is.. when i input integers in grade column1,1.25,1.50,1.75,2,2.25,2.50,2.75,3then Remarks will show PASSEDand when Grade is 4 upremarks 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 formulaIIF(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 likeCREATE TABLE ....... othercolumns,Grade ....,Remarks AS CASE WHEN Grade IS NULL THEN 'UNKNOWN' WHEN Grade <4 THEN 'PASSED' ELSE 'FAILED' END) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
raokikun
Starting Member
8 Posts |
Posted - 2011-08-28 : 03:00:59
|
thank you sir i will try it asap!i wish it works!! |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-28 : 03:13:00
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
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 tableno problem on connecting it to the visual basicbut when executingwhen i input gradesnothing happens to the remarks computed columnhow can i do that.. help siri really need this for my thesis.. in order to graduate |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-28 : 06:25:29
|
Can you show your create script?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
raokikun
Starting Member
8 Posts |
Posted - 2011-08-28 : 22:17:58
|
create database ccscreate 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 problemit doesnt work even with no errors or exceptions |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-29 : 00:39:34
|
its working for me. see below:-drop table studentcreate 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 allselect 'fdw',null union allselect 'aFS',2 union allselect 'zxvc',7 union allselect 'zV',5 union allselect 'abnzvxzxvm',3 select * from studentoutput------------------------------------P_Key Student_Number Grade Remarks----------- ----------------------------- ----------------- -------1 abnm 1 PASSED2 fdw NULL UNKNOWN3 aFS 2 PASSED4 zxvc 7 FAILED5 zV 5 FAILED6 abnzvxzxvm 3 PASSED ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
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 problemsir 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 sqlNOTE:i must add records using vb.net in a datagrid viewill give it a try again, hope this works for nowim 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 :) |
 |
|
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 decimalsir 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 onlinehave you tried it in vb.net? and is it working?i must not add records or grades using sqlNOTE:i must add records using vb.net in a datagrid viewill give it a try again, hope this works for nowim 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 helpTHANK THANK YOU VERY MUCH! ill give it a try now asap :)
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
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 |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-29 : 01:29:10
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|