473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to write sql query in asp.net code behind

How to write this select query in asp.net code behind


Expand|Select|Wrap|Line Numbers
  1. DECLARE @calls_table TABLE
  2.     (
  3.       ID INT ,
  4.       Division CHAR(1) ,
  5.       [STATUS] VARCHAR(50)
  6.     )
  7. INSERT  INTO @calls_table
  8.         ( ID, Division, STATUS )
  9. VALUES  ( 1001, 'A', 'Open' ),
  10.         ( 1002, 'B', 'Closed' ),
  11.         ( 1003, 'A', 'Closed' ),
  12.         ( 1004, 'C', 'Open' ),
  13.         ( 1005, 'C', 'Open' )
  14.  
  15.  
  16. SQL Query:
  17.  
  18.  
  19. SELECT  Division ,
  20.         SUM(CASE WHEN STATUS = 'Open' THEN 1
  21.                  ELSE 0
  22.             END) AS Open_Calls ,
  23.         SUM(CASE WHEN STATUS = 'Closed' THEN 1
  24.                  ELSE 0
  25.             END) AS Closed_Calls ,
  26.         COUNT(*) AS 'Total_Calls' ,
  27.         CONVERT(DECIMAL(5, 2), SUM(CASE WHEN STATUS = 'Closed' THEN 1
  28.                                         ELSE 0
  29.                                    END)) / COUNT(*) AS Closed_Calls_Perc
  30. FROM    @calls_table
  31. GROUP BY Division
Please kindly give me the answer as soon as possible.

Thanks
Sathik
Jul 16 '14 #1
0 913

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jay | last post by:
Hello everyone, I just got done taking a small course in ASP.NET and I'm completely sold. This is amazing compared to original ASP. My question is about the preferred method of coding the asp...
4
by: Jeronimo Bertran | last post by:
This may be a very simple question. I have some old java code that uses scripting to dynamically create a <MAP> in my HTML. <map name="Map"> <script> var i; for (i=0; i<arr.length; i++)
4
by: Nevyn Twyll | last post by:
Is there any way I can use a code-behind event (like a btn_Click event) to write some javascript into the Response? I was thinking of using Response.Write() to write the following code into the...
4
by: etropic | last post by:
Im confused I want an .aspx page to have a table with my data in it. At first I wrote FillTablew(); in my Page_Load even in the Code Behind file. I had it loop the db etc. and use Response.Write...
2
by: Steven K | last post by:
Hello, I am trying to learn how to use Code Behind. Essentially, the example of Block 1 and Block 2 are the same. The difference is that in Block 1 I explicitly set the parameter value to...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
1
by: kellyj00 | last post by:
We have clients who have not been exposed to SQL and have built a few thousand queries using the iSeries Query tool via their 5250 sessions. Is there any way to gather the code behind these...
1
by: archana | last post by:
Hi all, I am new to asp.net. I have one question regarding code- behind model. I have written page_load event in code behind as well as in aspx page. Means i am doing mixing of code-behind...
5
by: DaveRook | last post by:
Hello I have a website which sells 200 products. Currently I use a results.aspx page to display and the querystring tells the databas which prodcut to show! However, not so good for Google...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.