|
BalasubramanianK wrote: In my table
Date Amount TotalAmount
01/07/2008 10000 10000
01/07/2008 10000 5000
01/07/2008 10000 0
I am using the following queries separately.
Select Date, Count(*), Sum(Amount) From Table Group by Date
Select Date, Count(*), Sum(Amount) From Table Where Amount>TotalAmount And TotalAmount <> 0 Group by Date
Select Date, Count(*), Sum(Amount) From Table Where Amount>TotalAmount And TotalAmount = 0 Group by Date
How can I execute the above 3 mentioned separate queries in a single query to get the result like
Date TotalRecords Amount1 TotalRec Amount2 Tot Amount2
01/07/2008 3 30000 1 10000 1 1000
You are probably looking for something like this[^]
|
|
|
|
|
How to write the SQL DB connection string in namespace file.Then i wanna add that connection string like "using DBconn;" <<DbConn should be connection string>>
If you know that how to write DB Connection string using webconfig file also welcome.
BD is MSSQL 2005
Programing language : C#
Web development using ASP.Net
If some one know please reply me
Thank you..!!!
ReGRdZZZ
CheeN
|
|
|
|
|
|
difference between sql server 2000 and 2005, i am going to for quick review, if any once can tell me in simplified manner i will really appreciate him/her.
please max avoid to give links. please give quick reference differences between those
This is haneef.............................................................
|
|
|
|
|
Hi Good Guys!
I want to write a trigger which can iterate through each udpated column and check for a string match. if found then I need to rollback.
TIA
puranonnet@hotmail.com
www.ibrinte.com
|
|
|
|
|
|
Hello,
I have written following query.
select em.ticketid, em.tickettitle, em.handlerid, em.CUSTOMERID, em.departmentid, em.site, em.platform,
em.server, em.swrelease, em.generateddate, em.emergencyraiseddate, em.startdate, em.enddate, em.problemdesc,
em.rootcause, em.customerimpact, em.outageevidence, em.isfirsttime, em.workdone, em.techanalysis,
em.plannedaction, em.permanentfix, em.attid, e.EMPNAME, dept.DEPARTMENTNAME, cust.CNAME from emergencycallup em,
employee e, department dept, customer cust where em.DEPARTMENTID = '1' and em.handlerid ='test.emp' and
em.handlerid = e.empid and cust.customerid = em.customerid and dept.departmentid = em.departmentid
But this retrieves same row multiple times. If I simplify this to,
select em.ticketid, em.tickettitle, em.handlerid, em.CUSTOMERID, em.departmentid, em.site, em.platform,
em.server, em.swrelease, em.generateddate, em.emergencyraiseddate, em.startdate, em.enddate, em.problemdesc,
em.rootcause, em.customerimpact, em.outageevidence, em.isfirsttime, em.workdone, em.techanalysis,
em.plannedaction, em.permanentfix, em.attid from emergencycallup em where em.DEPARTMENTID = '1' and em.handlerid
='test.emp'
one record is retrieved only once. But here I'm loosing some details such as name.
How to modify this query so that I retrieve all data but records are not duplicated.
TIA,
Puneri
modified on Sunday, July 6, 2008 9:30 AM
|
|
|
|
|
There are 4 tables.
Emergencycallup contains employee id(handlerid), customer id, department id
for these 3 columns i've to get employee name, customer name and department name from table employee, customer and department respectively.
|
|
|
|
|
Hi
The two queries should return the same row count.
Examine the employee, customer and department table for duplicates.
Have you used primary key and foreign key constraints ?
Kjetil
|
|
|
|
|
hi
how can i transfering data of table with script?
|
|
|
|
|
rezarafiee wrote: how can i transfering data of table with script?
Write script to read data, and write a script to write data. Connect those 2 and wolla.
|
|
|
|
|
You can do this without a script.
INSERT INTO table2 (field1, field2, ..., fieldn) SELECT ..... FROM table1
|
|
|
|
|
Dear All,
I need to send an email every 30 minutes if Insert happenned...Any one plz can help???
I need this to be inside the SQL server 2005, this means when an Insert happens on 'myTable' and depending on some time, an Email is being sent to a specified person.
I just do not know where to go to implement such idea...
I searched over the Internet, but nothing is useful for this purpose.
Kind Regards
OBarahmeh
|
|
|
|
|
SQL Server has email functionality.[^] You need to setup a job that runs in every 30 minutes, checks for inserts and sends mail.
|
|
|
|
|
Dear Navaneeth,
I know there is email functionality in SQL server, and I tried it...but I could not make the scenario that check If Insert has happenned...
So I need a sample of how to check for Inserts on myTable, then I can do the part of sending email..
Also I need to send the last inserted rows on myTable as attachement or HTML inside the email sent.
Kind Regards
Kind Regards
OBarahmeh
|
|
|
|
|
obarahmeh wrote: .but I could not make the scenario that check If Insert has happenned...
Ok - Say your table has 2 columns, "id" and "name". Now to get latest items inserted and not emailed, we need to add one more flag say "emailed" which will have a value "y" if email is sent. When new rows are inserting, set this filed value as "n".
In your SQL job, you can select records which has "emailed" flag value as "n". These will be the records that are newly inserted and pending to be emailed.
Hope this helps
|
|
|
|
|
I've got a program that needs to insert lots of rows into a table, typically, anywhere from a couple hundred, to tens of thousands. As such, I'd like them to go as fast as possible, so I'm using a .Prepare() on my OleDbCommand. If I run the following code with the .Prepare() commented out, it works fine. If I un-comment the .Prepare(), when it gets to the .ExecuteNonQuery(), it ALWAYS fails with the same complaint:
System.Data.OleDb.OleDbException: Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query.
Even better, it works fine on Oracle. But SqlServer, not so much.
private bool SaveOccurance(ref OleDbCommand cmd, ref OleDbTransaction CurTrans)
{
if (cmd == null)
{
string stmt = @"
insert into work_occurance(
crew_size, due_date, due_fl, est_do,
job_qty, labor_time, location, occurance,
priority, reported_by, source_fl, job_reason,
work_req_no, first_date, last_date, span_fl,
avg_meter, avg_meter2, avg_fuel, labor_rate,
company, maint_lock, change_dt, change_login_user)
values(
?, ?, ?, ?,
?, ?, ?, ?,
?, ?, ?, ?,
?, ?, ?, ?,
?, ?, ?, ?,
?, ?, ?, ?)";
cmd = new OleDbCommand(stmt, Conn, CurTrans);
cmd.Parameters.Add("@crew_size", OleDbType.Integer);
cmd.Parameters.Add("@due_date", OleDbType.Date);
cmd.Parameters.Add("@due_fl", OleDbType.VarChar, 1);
cmd.Parameters.Add("@est_do", OleDbType.Double);
cmd.Parameters.Add("@job_qty", OleDbType.Integer);
cmd.Parameters.Add("@labor_time", OleDbType.Integer);
cmd.Parameters.Add("@location", OleDbType.VarChar, 6);
cmd.Parameters.Add("@occurance", OleDbType.Integer);
cmd.Parameters.Add("@priority", OleDbType.Integer);
cmd.Parameters.Add("@reported_by", OleDbType.VarChar, 11);
cmd.Parameters.Add("@source_fl", OleDbType.VarChar, 1);
cmd.Parameters.Add("@job_reason", OleDbType.VarChar, 1);
cmd.Parameters.Add("@work_req_no", OleDbType.Integer);
cmd.Parameters.Add("@first_date", OleDbType.Date);
cmd.Parameters.Add("@last_date", OleDbType.Date);
cmd.Parameters.Add("@span_fl", OleDbType.VarChar, 1);
cmd.Parameters.Add("@avg_meter", OleDbType.Double);
cmd.Parameters.Add("@avg_meter2", OleDbType.Double);
cmd.Parameters.Add("@avg_fuel", OleDbType.Double);
cmd.Parameters.Add("@labor_rate", OleDbType.Double);
cmd.Parameters.Add("@company", OleDbType.VarChar, 10);
cmd.Parameters.Add("@maint_lock", OleDbType.Integer);
cmd.Parameters.Add("@change_dt", OleDbType.Date);
cmd.Parameters.Add("@change_login_user", OleDbType.VarChar, 8);
foreach (OleDbParameter p in cmd.Parameters)
{
p.IsNullable = true;
}
}
cmd.Parameters["@crew_size"].Value = 1;
cmd.Parameters["@due_date"].Value = DateTime.Now;
cmd.Parameters["@due_fl"].Value = "F";
cmd.Parameters["@est_do"].Value = 314.15;
cmd.Parameters["@job_qty"].Value = 1;
cmd.Parameters["@labor_time"].Value = TimeSpan.FromHours(1.5).TotalMilliseconds;
cmd.Parameters["@location"].Value = "NORMM";
cmd.Parameters["@occurance"].Value = 3;
cmd.Parameters["@priority"].Value = 5;
cmd.Parameters["@reported_by"].Value = "FORECAST";
cmd.Parameters["@source_fl"].Value = "A";
cmd.Parameters["@job_reason"].Value = "S";
cmd.Parameters["@work_req_no"].Value = 1641781;
cmd.Parameters["@first_date"].Value = DateTime.Now - TimeSpan.FromDays(7);
cmd.Parameters["@last_date"].Value = DateTime.Now + TimeSpan.FromDays(4);
cmd.Parameters["@span_fl"].Value = "Y";
cmd.Parameters["@avg_meter"].Value = 0;
cmd.Parameters["@avg_meter2"].Value = null;
cmd.Parameters["@avg_fuel"].Value = 10;
cmd.Parameters["@labor_rate"].Value = 45;
cmd.Parameters["@company"].Value = "1";
cmd.Parameters["@maint_lock"].Value = 0;
cmd.Parameters["@change_dt"].Value = DateTime.Now;
cmd.Parameters["@change_login_user"].Value = "FORECAST";
ListParms(cmd);
try
{
int rows = cmd.ExecuteNonQuery();
return true;
}
catch (Exception E)
{
Console.WriteLine(E.ToString());
return false;
}
}
If anyone has any advice, I would be terribly grateful!
Thanks!
|
|
|
|
|
Hi.
Try change
cmd.Parameters["@first_date"].Value = DateTime.Now - TimeSpan.FromDays(7);
cmd.Parameters["@last_date"].Value = DateTime.Now + TimeSpan.FromDays(4);
to
cmd.Parameters["@first_date"].Value = DateTime.Now.AddDays(-7);
cmd.Parameters["@last_date"].Value = DateTime.Now.AddDays(4);
It should not work, but it have helped me before.
Kjetil
|
|
|
|
|
Thanks for the reply. I tried your suggestion, but I get the same error (and it still works fine if I do not Prepare() that command). My real program just supplies an already calculated date anyways (based upon things like an acceptable deviation range, avoiding weekends and holidays, etc), like:
cmd.Parameters["@first_date"].Value = this.earliest_date;
cmd.Parameters["@last_date"].Value = this.latest_date;
For now, I'm going to go with not preparing the statement, even if it will get called many thousands of times. It doesn't seem to make much difference in my testing so far (unlike with Oracle, where not Preparing that statement made it run significantly slower).
|
|
|
|
|
Hi.
Have you tried OleDbType.DBDate instead of OleDbType.Date ?
Worth a try.
Kjetil
|
|
|
|
|
Here is the code:
cn = null;
cn = new SqlConnection(cnStr);
SqlCommand cmdSet = new SqlCommand("SELECT * FROM MonthSet", cn);
SqlDataAdapter daSet = new SqlDataAdapter(cmdSet);
SqlCommand cmdHeader = new SqlCommand("SELECT * FROM MonthSetHeader", cn);
SqlDataAdapter daHeader = new SqlDataAdapter(cmdHeader);
SqlTransaction trnMonthData = null;
cn.Open();
trnMonthData = cn.BeginTransaction();
cmdSet.Transaction = trnMonthData;
daSet.UpdateCommand = cmdSet;
cmdHeader.Transaction = trnMonthData;
daHeader.UpdateCommand = cmdHeader;
try
{
daSet.Update(monthSet, "MonthSet");
daHeader.Update(header, "MonthSetHeader");
trnMonthData.Commit();
}
catch(Exception ex)
{
trnMonthData.Rollback();
return ex.Message;
}
finally
{
cn.Close();
}
return "";
I have played with the code to check the following"
1) Both datasets have changes
2) No exception returned
3) If I do only 1 update in the transaction, I can return the number of rows affected - correct.
4) This applies to both datasets
5) Rollback is not called
However, no changes are made to the database.
If I do the updates individually, using the same datasets, without using a transaction, the changes are made to the database.
Nigel
|
|
|
|
|
Any Oracle expert in here can guide us through the InstantClient steps in details?? I tried everything possible and I just gave up
ps. Please, do not link me to a website, I need your own experiences in this matter!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
hi
i'm using vb.net 2008 and database sql server 2005 ,, my connection string is as :
Data Source=ServerName; Initial Catalog=DataBaseName ;User ID=sa;Password=1111"
it's ok and works as good ,,,
but when i test exe project on client pc ,, an error with the connectoin string ,
this problem has happend with me before with sql server 2000 and i solved by add
Network=DBMSSOCN;
to the connection string ,
but with sql server 2005 it still doesn't work ,,
what's is the correct connection string to allow the client coneects the server
thanks
jooooo
|
|
|
|
|
kindman_nb wrote: an error with the connectoin string ,
What was the error ? Take a look at Connection strings[^]
|
|
|
|
|
I am using MSSQL and I have a value named NUG(4'') in a field named Sz in the table tbl_Sz.
But when i use the query -> Select count(*) from tbl_Sz where Sz='NUG(4'')', it gives the count zero, which should be one in this case.
Is the count is zero due to NUG(4'') has two Apostrophes ? Because I think sql ignores the string after the Apostrophe or something like that?
If it is so then how to solve this problem ?
|
|
|
|
|