School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,220 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,647 people online right now. Registration is fast and FREE... Join Now!




SQL Query Branching

 

SQL Query Branching

Daiken

29 Jan, 2008 - 02:34 PM
Post #1

New D.I.C Head
*

Joined: 22 Sep, 2007
Posts: 27



Thanked: 1 times
My Contributions
I am trying to turn certain fields of a Gridview control invisible based on the the values from a certain data field within my database.

In order to do so I require a bool value, however the value indicating if it should be visible or not is an integer.

I was trying to convert the value, within my sql statement, as I do not have direct access to the database in order to
insert the value I need.

The field "MyValue" will return a value between 0 and 5. If it is 0 it should return "False" if anything else it should be "True"/

This is my sql statement:
CODE

SELECT name, city, mallName, companyName, contactName, projectID, substantialcompletiondate, worktype,  IF(MyValue>0, "TRUE", "FALSE") FROM dbo.qryProjectsListForWebsite WHERE (province = @province) ORDER BY name


I get an except from this, due to the if(,) branching.


Any help would be appreciated.

User is offlineProfile CardPM
+Quote Post


baavgai

RE: SQL Query Branching

29 Jan, 2008 - 03:27 PM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 4,351



Thanked: 412 times
Dream Kudos: 550
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
Try
CODE

SELECT name, city, mallName, companyName, contactName, projectID, substantialcompletiondate, worktype,  
        (case when MyValue>0 then "TRUE" else "FALSE" end) as myValue
    FROM dbo.qryProjectsListForWebsite
    WHERE (province = @province)
    ORDER BY name


Note, if you want it interpreted as a boolean, you may also want to try (case when MyValue>0 then 1 else 0 end) as myValue.

Hope this helps.

User is offlineProfile CardPM
+Quote Post

Daiken

RE: SQL Query Branching

30 Jan, 2008 - 10:18 AM
Post #3

New D.I.C Head
*

Joined: 22 Sep, 2007
Posts: 27



Thanked: 1 times
My Contributions
The latter suggestion worked perfectly, thank you.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 10:24PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month