473,406 Members | 2,273 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,406 software developers and data experts.

ASP & SQL problem to split values into separate columns

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
Jul 16 '07 #1
4 1852
jhardman
3,406 Expert 2GB
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
Jul 16 '07 #2
Can you help me with that ASP code? That is the part I am struggling with really.
Thanks
Jul 17 '07 #3
danp129
323 Expert 256MB
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
Expand|Select|Wrap|Line Numbers
  1. 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
  2. from rentals b
  3. WHERE Name LIKE '%City%' AND (YEAR(Date) = '2007')
  4. GROUP BY b.Date
  5.  
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
Jul 17 '07 #4
thanks that works perfectly now!

M
Jul 18 '07 #5

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

Similar topics

0
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...
2
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...
1
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...
0
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!...
0
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...
15
RMWChaos
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...
0
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...
7
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

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.