|
In which case it sounds like you need two queries:
SELECT orderTableID, orderUserID, SUM(orderPrice) AS TotalPrice
FROM tbl_Orders
WHERE orderPaid = 1 AND DATE BETWEEN 'date1' AND 'date2'
GROUP BY orderTableID, orderUserID
SELECT orderCategory, SUM(orderPrice) AS CategoryPrice
FROM tbl_Orders
WHERE orderPaid = 1 AND DATE BETWEEN 'date1' AND 'date2'
GROUP BY orderCategory If you need your second query broken down by table and user as well, put orderTableID and orderUserID in the GROUP BY clause.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Mike,
Thanks for that mate! Sorry i dint reply sooner, but im working on a big project and only just got chance to try them out.
They are both excellent, and need, but not quite what i was after. My fault for getting myself confused and giving the (slightly) wrong info.
Using the code you gave above, but more specfic to my example data in my DB i have:
SELECT orderCategory, SUM(orderPrice) AS CategoryPrice FROM tbl_Orders WHERE orderPaid = true AND (orderTime BETWEEN '2006/04/12 02:35:08' AND '2006/04/12 06:31:29') AND orderTableID = '22' AND orderUserID = 'dong' GROUP BY orderCategory <br /> This shows the subtotals for each of the item types ordered by Mr Dong on Table 22.
However, what i didnt explain very well was that i need to group and display the items by name and total price also. So for example imageine the following:
orderTableID | orderUserID | orderMenuItem | orderCategory | orderPrice
22 Dong Chips Tapas 2.50
22 Dong Chips Tapas 2.50
22 Dong Beer Bebidas 3.00
22 Dong Wine Bebidas 7.00
So the output from the SQl should look like
2 Chips Tapas 5.00
1 Beer Bebidas 3.00
1 Wine Bebidas 7.00
Etc. Hopefully this makes sense. If you could sort me out with SQL for this mate, i would be truly grateful, and post you a pack of M&M's as a thank you!
:-> :->
<---if only i were but clever!
|
|
|
|
|
Hi,
I installed Oracle Ex (express),created a password for the default system user etc. But now when I click on the "Go to database homepage" button in the start menu under "Oracle Database 10g Express Edition" it opens my browser with the following url: http://127.0.0.1:8080/apex. and this results in a page cannot be displayed error. It's suppost to bring up the management console! What am i doing wrong? there isn't any web file in the setup forder anyhow...
Lastly, when connecting manually in console mode, it doesn't want to accept my password input. Why?
Can anyone please help!
Regards,
Tintin
|
|
|
|
|
Hi,
Please help!
I need to retreive the supplier name from the suppliers table, number of devices sold by the particular supplier by using devices table, no. of failures to the particular supplier by using the failures table.
I can able to retreive the supplier name and the number of failures but i can't able to retreive the number of devices sold by the particular supplier.
I tried the following code
select suppliers.sname, count(*) i, (select count(*) from devices,suppliers where devices.suppid=suppliers.suppid) j from failures,devices,suppliers where devices.suppid=suppliers.suppid and failures.deviceid=devices.deviceid group by suppliers.sname
The problem is the j column will display total no of rows. I need to get the count of devices that are sold by the particular supplier. How can i get the suppliers.suppid value that is used outside?
Hope you understand the problem.
Thanks
|
|
|
|
|
how do i lock a Table in MS SQL SERVER?
krishna
|
|
|
|
|
check this
http://www.mssqlcity.com/Articles/Adm/SQL70Locks.htm#part_3
|
|
|
|
|
In VB.NET, the data of a grid is associated with a table("tblUser"),
tblUser, and tblUserPrivilege are relational tables, while I modify the data of the grid, it'll throw an SqlException because of the relation,
my question is:
how can i update these two tables?
...waiting for some solutions, ...
|
|
|
|
|
I have installed MSDE2000 and how can i see as server in SQ Server Enterprise Manager also how can i view Databases in this server.
|
|
|
|
|
Search for SqlBuddy in google
|
|
|
|
|
|
|
hi
It seems that my code can insert data into memory, but not into the database. What I mean is that after "insert data", I can "read data",
which I just insert. When I check the actual database table, it didn't
get updated.
I am using VS 2005 and table designer. Regarding to this problem, is
it related to any setting of setup of the database? I check the code,
and I have no idea how it occurs.
private static string connectionString = null;
private static SqlConnection connection = null;
private static string commandString = null;
private static SqlCommand command = null;
private static SqlDataReader reader = null;
static void Main(string[] args)
{
connectionString = ConfigurationManager
.ConnectionStrings["appDatabase.Properties.Settings.databaseConnectio nString"]
.ConnectionString;
connection = new SqlConnection(connectionString);
try
{
// Insert data
commandString = @"INSERT INTO userTable
(userID, permissionLevel, mobile, emailAddress, mailAddress, pager) VALUES(1, 2, '123', 'aa@a.com', 'oz', 'no')";
SqlCommand command = new SqlCommand(commandString, connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
// Read data
commandString = @"select * from userTable";
command = new SqlCommand(commandString, connection);
connection.Open();
reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader["permissionLevel"].ToString());
}
connection.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
regards
figo2476
|
|
|
|
|
The only thing I can think of - if you're sure that you're looking at the right database - is that you've got the implicit transactions option turned on. This automatically creates a transaction when you first execute a data modification statement (INSERT, UPDATE, DELETE). If you don't execute a COMMIT TRANSACTION statement, it'll be rolled back when the connection gets closed. Also, other connections won't see the modification due to transaction isolation, unless they use the READ UNCOMMITTED level or NOLOCK hint (not recommended). The SELECT statement in your code can see it, I conjecture, because the connections are pooled - when you call connection.Open() the second time, you're getting the same underlying connection back from the pool, which hasn't actually been closed in the meantime, so the transaction is still open.
I wouldn't recommend using the implicit transactions option.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
hai,
Iam new to sequel server and any database related projects.
now i need to work on sequel server . plz guide me where do i get online help for sequel server and what r the books to prefer?
please guide me regading this.
krishna
|
|
|
|
|
internet: www.sqlservercentral.com or the Book online installed with the sql server
|
|
|
|
|
|
Hi
How to get value from some for example dropdownlist control who is insert into gridview control.I need that for update commanand.Pleas help me,
good bye and hava a nice day.
|
|
|
|
|
You have to be more specific in your request and is this really a SQL db problem ?
|
|
|
|
|
Hey guys,
I have four tables UniversityDB(main Table), UniSourceDB, UniMajorDB, CDDB.
All four tables have the field "UniCode" in common, I want to select fields from four tables
I used this comand >>>
string cmd = "SELECT UniversityDB.UniID, UniversityDB.UniCode, UniversityDB.UniName, <br />
UniversityDB.UniCity, UniversityDB.UniState, UniversityDB.UniAddress, <br />
UniversityDB.UniDetail, UniMajorDB.Major, UniMajorDB.Level, UniSourceDB.SourceName, UniSourceDB.Year, CDDB.CDNumber, CDDB.Year FROM UniversityDB, UniMajorDB, UniSourceDB, CDDB where UniversityDB.UniCode = '" + UniCode_tb.Text + "' and UniversityDB.UniCode = UniMajorDB.UniCode and UniversityDB.UniCode = UniSourceDB.UniCode and UniversityDB.UniCode = CDDB.UniCode";
The problem is that if one of UniSourceDB, UniMajorDB, CDDB don't have any value that match
UniCode_tb.Text, then it wouldn't be shown ?
Can you please help me out and give me a better select command so i don't have this problem.
Thanx
Mr.K
|
|
|
|
|
Here is one possible solution:
string cmd = "SELECT UniversityDB.UniID, UniversityDB.UniCode, UniversityDB.UniName,<br />
UniversityDB.UniCity, UniversityDB.UniState, UniversityDB.UniAddress,<br />
UniversityDB.UniDetail, UniMajorDB.Major, UniMajorDB.Level, UniSourceDB.SourceName, UniSourceDB.Year, CDDB.CDNumber, CDDB.Year FROM UniversityDB LEFT JOIN UniMajorDB ON UniversityDB.UniCode=UniMajorDB.UniCode LEFT JOIN UniSourceDB ON UniversityDB.UniCode=UniSourceDB.UniCode LEFT JOIN CDDB ON UniversityDB.UniCode=CDDB.UniCode WHERE UniversityDB.UniCode = '" + UniCode_tb.Text + "'";
This assumes that the UniversityDB table will always have a record.
----------
There go my people. I must find out where they are going so I can lead them.
- Alexander Ledru-Rollin
|
|
|
|
|
SELECT DB.UniID,
DB.UniCode,
DB.UniName,
DB.UniCity,
DB.UniState,
DB.UniAddress,
DB.UniDetail,
MDB.Major,
MDB.Level,
SDB.SourceName,
SDB.Year,
CDDB.CDNumber,
CDDB.Year
FROM UniversityDB DB
LEFT JOIN UniMajorDB MDB
ON MDB.UniCode = DB.UniCode
LEFT JOIN UniSourceDB SDB
ON SDB.UniCode = DB.UniCode
LEFT JOIN CDDB
ON CDDB.UniCode = DB.UniCode
WHERE DB.UniCode = '" + UniCode_tb.Text + "'
|
|
|
|
|
Thanx guys
|
|
|
|
|
hi
i am not able to deploy my asp.net app on iis ,it says login failed for sameer\aspnet,pls help,i not able to make hw to add it
sameer
|
|
|
|
|
The particulars: I have a 2.0 ASP/C# app, making use of Sql Server 2000 on the back end. There are 3 actual machines in play here:
1. DB server - windows 2003, Sql Server 2000
2. Web server - windows 2003
3. My own work station - windows 2003
The app works fine on my computer (which doubles as a testing machine), interacting with the database on the DB Server. When I upload it to the webservcer, however, problems arise.
It's a simple app, and everything works except one specific thing in the admin section: editing information (it's a membership directory for a client). You can add and delete no problem; additionally both the searches in the admin section as well as the public search functionality work no problem. Detail viewing (see below) works no problem. The page itself has a simple searching mechanism, a gridview to display results of a search (including partial matches), and then a details view (dvMember) for the specifics of a result. dvMember is bound to a datasource, dsMember. dsMember has Select and Update commands - both stored procs. dvMember is a mishmash of boundfields and templatefields currently. It relies on dsMember for switching between edit/viewing mode.
When I try to edit a member on the production server, I get the following error message:
"@original_MemberID is not a parameter for procedure spEditMember. "
Well, that's correct. There is no such paramater for spEditMember. Furthermore, there's no such data anywhere inside the control or on the page. spViewMember is the select command, and it pulls no such thing out of the database. I have no idea where this is coming from. There is a MemberId paramater, it's the PK for tblMember int he database. Again, the proc itself lacks the referenced parameter in the error message. Again, this works on my machine. But when I move it to the production server, nada. I'm not sure where to look for the cause of the problem. I haven't found anything crazy on the .aspx page or in the codebehind. Is it some difference between how things are set up on the live server and how they're set up on mine?
|
|
|
|
|
Hi
My question is when i have it some datagrid and in this data grid i have dropdownlist how to get selected value of dropdownlist and to put in update command?
best regards
|
|
|
|
|