Hi,
I have a query where I select all the values from my MS SQL table that are LIKE a certain string. The query works, but in the ASP page, I only want to write the date once, while writing the values from the other column in all cases.
To illustrate, i have a table that looks like this:
ID Date Name
1 2007/01/01 city_house
2 2007/01/02 city_farm
3 2007/01/02 city_house
4 2007/01/02 city_house
5 2007/01/02 city_farm
my sql is basically
SELECT COUNT(*) AS countcity, date, name
WHERE Name LIKE '%City%') AND (YEAR(Date) = '2007')
GROUP BY b.Name, a.Date
ORDER BY a.ChatDate
The query returns as expected all the data that matvches that criteria, i.e
countcity date name
1 2007/01/01 city_house
2 2007/01/02 city_farm
2 2007/01/02 city_house
etc.
The desired outcome of my ASP page is that I can use the query to get the Name column split into one for city_house and one for city_farm.
Date City_House City_Farm
2007/01/01 1 0
2007/01/02 2 2
How can I achieve this with ASP? Is there a better SQL query to use to achive this?
Thanks
4 1862 jhardman 3,406
Recognized Expert Specialist
I can't think of a different sql query to get that result. In asp I usually handle this by setting a variable equal to the date and checking each entry against the variable. If the entry has the value already stored in the variable, I don't print the date. If the entry has a different value, I print the date, and update the variable before I go on. Does this make sense?
Jared
Can you help me with that ASP code? That is the part I am struggling with really.
Thanks
danp129 323
Recognized Expert Contributor
With this data in table "rentals":
ID Date Name
1 2007/01/01 city_house
2 2007/01/02 city_farm
3 2007/01/02 city_house
4 2007/01/02 city_house
5 2007/01/02 city_farm
Using this Query - SELECT b.date, sum(case when b.name like '%house%' then 1 else 0 end) as City_House, sum(case when b.name like '%farm%' then 1 else 0 end) as City_Farm
-
from rentals b
-
WHERE Name LIKE '%City%' AND (YEAR(Date) = '2007')
-
GROUP BY b.Date
-
Will return this recordset
Date City_House City_Farm
2007-01-01 00:00:00 1 0
2007-01-02 00:00:00 2 2
thanks that works perfectly now!
M
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Frank Collins |
last post by:
Can anyone point me to some good examples on the web of
using values from dynamically created checkboxes on forms
in ASP, particularly relating to INSERTING those values
into a SQL or Access database?
Basically, I have a form on which I have a series of
statements, with 3 checkboxes for each statement - YES,
NO, MAYBE. This series of statements is being dynamically
populated from a query of a table in Access,
called "tblQuestions". In...
|
by: Stuart |
last post by:
Hi All,
Can anyone help.
Q1. How do I send 2 dates to a stored query in access. What I have in the
query so far is
Select * from tblOrders where Date_Archived between #3/01/04# and #3/31/04#
What I want is to send to variables to this query that the user inputs.
|
by: ratnakarp |
last post by:
Hi,
I have a search text box. The user enters the value in the text box and
click on enter button. In code behind on button click i'm writing the
code to get the values from the database and binding it to a repeater
control. This repeater control has multiple text boxes and buttons. Can
you please tell me how can i do paging in this case ?
I'm posting my code below. The problem is that if i click on
"AdjustThisAd" button, it opens...
|
by: Kevin Bartz |
last post by:
-----Original Message-----
From: Kevin Bartz
Sent: Monday, August 09, 2004 10:37 AM
To: 'mike@thegodshalls.com'
Subject: RE: Out of swap space & memory
Thanks for your reply, Mike! Theoretically, I should need only six of the
columns, but as a means of verifying integrity, I would like to de-dup using
all the columns. For instance, if there are two rows identical everywhere
but some column outside the six, I would like to know about...
|
by: ward |
last post by:
Greetings.
Ok, I admit it, I bit off a bit more than I can chew.
I need to complete this "Generate Report" page for my employer and I'm
a little over my head. I could use some additional assistance. I say
additional because I've already had help which is greatly appreciated.
I do try to take the time and understand the provided script in hopes
on not having to trouble others on those. But here it goes...
| |
by: RMWChaos |
last post by:
In my ongoing effort to produce shorter, more efficient code, I have created a "chicken and egg" / "catch-22" problem. I can think of several ways to fix this, none of them elegant.
I want my code to declare var stop if it was not passed to the function. The problem is that stop would be equal to a value dependent on var index that has not been declared yet, but index cannot be created until stop is declared. So you see my chicken and egg...
|
by: Taxman |
last post by:
Windows XP, MS Office Excel 2003
If the tasks, I’m trying accomplish have been addressed previously (separately or in combination). Please, provide the links or keyword search to find them. I’ve been searching for code for each part of the task separately and trying to piece together multiple macros, that do something similar, to what I’m trying to accomplish in my over all task, but I’m not having a lot of luck. So, here’s the entire task,...
|
by: kimmelsd33 |
last post by:
I am using VB6. I want to read a tab delimited file, and assign each column value into a variable. If the variable is "-999.25", I want to make it a "0". I then want to reassemble the values, and write them to a temp text file. Starting with line 64, I have about 28 columns and x number of rows. Ex: 1000<tab>23.3<tab>-999.25<tab> etc. The value of -999.25 can be in any column. I need to replace it before it is stored in the variable. I need to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |