?
Solved

IF.., Then in ASP

Posted on 2012-08-19
3
Medium Priority
?
625 Views
Last Modified: 2012-08-23
Team -

I have a table in sql called "Goals" where i have the following columns & values

Goal - Varchar(255)
GoalTarget - Varchar(255)
PI1Value - Varchar(255)
PI1Symbol - Varchar(255)

Values:
Accuracy
98
97
>

I have another table in sql called "Goalsheet" where the following columns and values are updated.

Goalsheet
Goal - Varchar(255)
GoalAchieved - Varchar(255)

I want to do a If Then statement in asp

If Goalachieved & PI1Symbol & PI1Value Then
PIScore = 1
Else
....
End if

However I'm getting error. "Type mismatch: '[string: "98<97"]' "

Please help..,

any help from sql side also would be great, kindy help.
0
Comment
Question by:davidi1
3 Comments
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 38309753
You can use the eval function

<%
GoalTarget = "98"
PI1Value = "97"
PI1Symbol = "<"

' option 1 *************************************

sql=cdbl(GoalTarget) &  trim(PI1Symbol) &    cdbl(PI1Value)
if  eval(sql ) then
	response.write "Its true"
	else
	response.write "it's false"
end if


' option 2  *************************************
response.write "<hr>"
if testit GoalTarget, PI1Value, PI1Symbol = 1 then
	response.write "function true"
	else
	response.write "function false"
end if

' fuction can go anywhere on your page, top bottom or middle.  Best to put them all in one spot or maybe as an include file
function testit(GoalTarget,PI1Value,PI1Symbol)
sql=cdbl(GoalTarget) &  trim(PI1Symbol) &    cdbl(PI1Value)
if  eval(sql ) then
	testit =1
	else
	testit =0
end if

end function


%>

Open in new window

0
 
LVL 14

Accepted Solution

by:
nishant joshi earned 1500 total points
ID: 38309769
in direct asp you can not converiot string to boolean value,

means
If Goalachieved & PI1Symbol & PI1Value Then

Open in new window

in above code Goalachieved & PI1Symbol & PI1Value is a string not a boolean for that you can not use it,
in sql your code should be:
SET @sql='If '+Goalachieved+PI1Symbol+PI1Value+'Then
BEGIN
PIScore = 1 
END
Else
....

Open in new window


Thanks..
Nishant
0
 
LVL 2

Author Closing Comment

by:davidi1
ID: 38323973
used your method to create a Stored Proc..,
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question