I would like to create a column that displays if a student has passed or failed. To pass the overall grade needs to be above 40.
I have done this before using access using the following:
IIf([Overall]<=40,"fail","pass")
But I’m very new to visual basic. Anyone got any ideas on how I can do this?
The IDE I am using is Visual Studio
This is the table
Or if there are any tutorials that you would recommend that would be great.
You can do it in your table definition:
You can use a CASE WHEN statement to check for a criteria and provide a value.
You can not refer to a computed column in another computed column.
So you can add a column like this:
[ColumnName] AS CASE WHEN (the formula for overall) <= 40 THEN 'fail' ELSE 'pass' END
Also you can make the result as a bit (boolean) data type and let the application decide to show a string instead of true or false.
Related
I have a handful of scalar-valued functions (which I appreciate may not be best practice, but for now, this will suffice, this is simply a development exercise) which I use within various computed columns with MS SQL tables.
I have a scenario whereby I need to use the result of one of these functions, as a parameter to another within a given computed column. For example;
(case when [DynamicQuantity] IS NULL then ([dbo].[GetFiatValue]([Currency],[Quantity])) ELSE ([dbo].[GetFiatValue]([Currency],([dbo].[getStakedQuantity]([currency])))) end)
If the given [DynamicQuantity] field is null (a column value generated by another SVF), use the [Quantity] field. However, if [DynamicQuantity] is populated, the ELSE will fire, and pass the output of the [dbo].[getStakedQuantity] SVF in place of the [Quantity] value.
Is this achievable? I can't seem to get the syntax to work and am questioning whether this is even possible?
Running it via a normal query works;
SELECT case when [DynamicQuantity] IS NULL then [dbo].[GetFiatValue]([Currency],[Quantity]) ELSE [dbo].[GetFiatValue]([Currency],[dbo].[getStakedQuantity]([currency])) end from dbo.cryptoPortfolio
But when used as a computed column formula below;
case when [DynamicQuantity] IS NULL then [dbo].[GetFiatValue]([Currency],[Quantity]) ELSE [dbo].[GetFiatValue]([Currency],[dbo].[getStakedQuantity]([currency])) end
SSMS will not accept it, with Error validating the formula for column 'FiatValue'.
I have a table with two columns hora_entrada and hora_saida and when running this select statement:
select hora_entrada, hora_saida
from Controlo_de_Entrada_saidas
it shows this result:
What I want to do is to combine these two columns into one that if Hora_saida = "Não saiu", it shows the data in hora_entrada but if hora_saída has an actual hour in there, it shows the data in hora_saida instead.
So basically this should be my result:
I don't know if I'm making myself clear, I actually don't even know where to start or if its even possible but any help would be appreciated.
Try using a CASE expression:
SELECT
hora_entrada,
hora_saida,
CASE WHEN hora_saida = 'Não saiu'
THEN hora_entrada ELSE hora_saida END AS new_column
FROM yourTable;
This logic assumes that any value in the hora_saida column which is not Não saiu is a valid timestamp. If not, then we could add additional logic to check for this as well.
If you are open/able to changing your data model, you might want to consider just storing NULL values for the missing data. SQL Server (and most other databases as well) has a built-in function COALESCE, which can be used to replace NULL with a backup value. This would avoid needing to use a lengthy CASE expression as you see above.
I am trying to convert the following SQL Server expression into a visibility expression in SSRS for a certain textbox that contains an error message:
select address, commonPlaceName, municipality where #Location not like '$[0-9]%'
My SSRS report lets users search for #Location, which is a combination of the address and commonPlaceName and returns a table of records.
I am trying to limit the number of rows returned based on both the character length and whether the parameter value supplied contains a number.I want to show an error message when they search for a common place or address without a number that says "Sorry your search was too broad so the number of records has been limited".
I got the length part to work by using the following:
=iif(len(Parameters!Location.Value)<=5,false,true)
But I can't figure out how to search for a number in a string
For those interested, in the SQL script, I am setting the rowcount based on a case statement that parallels the visibility options I am trying to set in SSRS.
I am still learning SSRS so any help is much appreciated!
EDIT:
Below is the SQL statement I am using to limit rowcount if that helps:
declare #top int
set #top = case when len(#Location) <= 5 then 100
when #Location not like '%[0-9]%' then 100
when len(#Location) >5 then 0
end
set rowcount #top
There are a number of ways to do this.
Calculate the visibility in your query and set the Visibility to the calculated query field. This is cleaner in the report. Normally you would want to put all display logic in the report itself, however, I have been lazy a time or two.
=IIF(Fields!ShouldShowField.Value==1,0,1)
Use SSRS functions such as InStr() or
=IIF(Regex.Replace(Fields!MyField.Value, "[MyRegExString]").Length == Fields!MyField.Value.Length, 0, 1)
Use Custom Code for advanced string manipulation and call your code similar to
=IIF(Code.ShouldShowTextBox(Fields!MyField.Value),0,1)
Okay I think I found a workaround for now. I ended up creating a new dataset:
select
'LocationWithNum' = case
when #Location like '%[0-9]%' then 'true'
else 'false'
end
Then I changed the visibility expression of the error message textbox to the following:
=iif(len(Parameters!Location.Value)<=5 or First(Fields!LocationWithNum.Value, "LocationWithNum") = false, false, true)
So far this seems to work well. Let me know if you guys think of anything else!
I am using Microsoft SQL Server Report Builder 3.0. I have created a Stored Procedure (stored_procedure1) in the database which has a Parameter (parameter1). Here, stored_procedure1 returns result1.
Then, I used stored_procedure1 to create a Dataset (dataset1) in the Microsoft SQL Report Builder 3.0. Next, I created a Table (table1) in Microsoft SQL Report Builder 3.0 with 2 rows and 2 columns (total 4 cells).
I would like to fill each element of table1 with result1 from dataset1. Hence, I set expression of each cell of table1 as follows:
=Sum(Fields!result1.Value, "dataset1")
When I run this report, it works perfectly and asks me to enter parameter1. However, I want to use single Dataset (dataset1) with different values of parameter1 for each cell of the table. Hence, I want to pass/set parameter1 with unique parameter_value for each expression of table cells. Say I want to set parameter1 = parameter_value1 for first cell.
For example, if I need to set parameter_value = 5, I did something like
=Sum(Fields!result1.Value, "dataset1"), Parameters!parameter1.Value = 5
I also tried following:
=Sum(Fields!result1.Value, "dataset1") & Parameters!parameter1.Value = 5.
It doesn't work.
In summary, I coudln't pass or set parameter value together with an expression.
Can we set/parameter value.
I would like to thank you in advance.
If anyone got stuck with this problem, I found a way around for this. T
here is no way one can pass parameter within expression.
You will need to create a subreport to do this. You can pass parameter to subreport.
Its little time consuming. However, it seems there is no other way around.
Hi Having a syntax issue - at least I think it is. I want a default date as part of a case statement inside a materialised view (MS SQL 2008 +):
, CASE
WHEN WithFirstDate = 0 THEN CONVERT(DATE,'1900-JAN-1', 101)
WHEN WithFirstDate = 1 THEN
Start1
ELSE --WithFirstDate = 2
Start2
END ValidDate
I'm getting the following error:
view uses an implicit conversion from string to datetime or smalldatetime. Use an explicit CONVERT with a deterministic style value
I'd like to have a solution that works irrespective of localization (i.e US style dates, Japanese style dates and the rest of the world)
Thanks
Instead of:
CONVERT(DATE,'1900-JAN-1', 101)
Just do:
CONVERT(DATE,'1900-01-01')
However the issue may be with the other two columns, Start1 and Start2. I am guessing these are not DATE columns.
The 101 code you are passing the CONVERT function does not match your format. Check the following link to find the correct code:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
Ok well this forum has gone downhill IMHO, first my post get endless edited for grammar which doesn't change the meaning, then it gets voted down presumably because it was "to difficult" to answer. https://stackoverflow.com/users/61305/aaron-bertrand was on the right lines. Thanks Aaron. The problem was a computed column in one of the referenced tables was non deterministic. This error only resolved in a flag when the materialising clustered index was being created on the view. I'd post a link to the full answer but not allowed. Shame I cant recover all my old badges and points from a couple of years ago. Full answer here http://tinyurl.com/knor8qk