|
T.Senthilnathan wrote: I got a solutions.
Glad you got that. BTW why don't you post that solution in your message....Also are you sure your solution is best?
|
|
|
|
|
hello
i need help i am working on database and i have connected it to the c# i need small thing i have created a serach button but i dont want to show the result on data grid view if u can help plz give me the answer and the code
ty
|
|
|
|
|
Cross posting[^] in the C# forum won't help much.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
|
Hi all
I want to count records in a table respect to each date.
select count(id), add_date from packages group by add_date
this gives results only for dates which has exist.
Say I want to find the count in a range of dates, and if records not found then the count as zero.
Is it possible to do this with MySQL
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hi,
Perhaps the easiest way could be that you create a new table, for example SingleDate and add all necessary dates to that table. After that, using outer join, join the data between the date table and your table. So something like:
SELECT ...
FROM SingleDate d LEFT OUTER JOIN Packages p
ON d.Date = p.Add_Date
GROUP BY d.Date
|
|
|
|
|
Thanks for the comment.
Should I do with a temporary table or create a table in the database permanently? I've tried the following.
CREATE TEMPORARY TABLE date_col (add_dates nvarchar(50));
INSERT INTO date_col (add_dates) VALUES('2011-04-06');
SELECT * FROM date_col;
But stuck with two things.
1. How can I loop the date range and add all the dates into the table
2. I think to be in safe side I want to drop the table after the query required data, isn't it?
I appreciate your help all the time...
CodingLover
|
|
|
|
|
I would do it permanently since most likely this is not the only case when you need the dates.
To fill the table. Why not create a stored procedure. If you need to fill for a specific period again then you can use the same procedure. Something like:
CREATE PROCEDURE DateFill(d1 DATE, d2 DATE)
BEGIN
SET @d3 = d1;
REPEAT
INSERT INTO DateTable (date_co) VALUES (@d3);
SET @d3 = DATE_ADD(@d3, INTERVAL 1 DAY);
UNTIL @d3 > d2
END;
For dropping the table, I wouldn't since if the table is created and permanent you can continue to use it later. Just add a long enough date range to the table (say, 500 years )
Also it might be a good idea to add an index to the table to speed up the usage: http://dev.mysql.com/doc/refman/5.1/en/create-index.html[^]
|
|
|
|
|
Actually I don't want to keep records for a long time. Only for an instance.
The requirement is, for few sales rep I want to find the sales in a date range. That is for each sales rep I want to find the sales in a date range.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: The requirement is, for few sales rep I want to find the sales in a date range
This is a different thing. What I'm saying is that consider populating the table with long enough date range. And when you use the table take only the relevant portion of dates from it using proper WHERE condition. For example:
SELECT ...
FROM DateTable dt LEFT OUTER JOIN MyTable mt
ON dt.DateColumn = mt.DateColumn
WHERE dt.DateColumn BETWEEN @startdate AND @enddate
This way you can reuse the same data every time you fetch data for a new date range without having to re-create the dates.
|
|
|
|
|
Oh, I think I got your point now.
What you are saying is keep dates in a permanent table ( for a long dates, eg: 2000-01-01 to 2500-01-01) and use that table to join with the other table in the date range I want to.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Exactly
|
|
|
|
|
Thanks buddy.
I'll give a try and let you know.
So I'll keep this thread as it is.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Step 1: Create a table variable with a date column and fill the table with the date range that you need (probably the min and max dates from 'packages' table)
Step 2: Use your query and do a union with the temp table created in step 1
|
|
|
|
|
Shameel wrote: Step 1: Create a table variable with a date column and fill the table with the date range that you need (probably the min and max dates from 'packages' table)
So I can move with a temporary table or a permanent one. But I'm stuck with how to insert range of dates into it. Something like this ...
CREATE TEMPORARY TABLE date_col (add_dates nvarchar(50));
INSERT INTO date_col (add_dates) VALUES ('2011-04-06' through '2011-04-01');
I appreciate your help all the time...
CodingLover
|
|
|
|
|
|
|
Hi all,
My web application base on money transactions. My client wants to keep a realtime backups. That means i host the web app in one server and have another server for backups. If system down in the hosted server there is a backup link to the system in backup server. The problem is i want to update the backup server database in the same time when updating the original server database. What is the best and more efficient solution for this requirement.
thanks
|
|
|
|
|
|
This is a standard setup for a high a proficiency site, you need mirroring (as Mika suggested) and more probably failover web and database servers. I would suggest talking to a hosting site, it may be simpler to pay someone else to do these.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Good addition Marked as good answer.
|
|
|
|
|
In our application the user can define custom "user defined type" called "data context" to store a bunch of named datetime/string/number/list(Guid)
such as (for example)
--
Contact Information
Name
Age
Address
Birthday
--
we store that in the DB with some table like that (simplified version)
Sets -- a such item, ex: a contact information
id Guid
idDef Guid -- PK to the type definition table
SetValues -- store the values, ex: Contact.Name
id Guid
idSet Guid -- PK to a record in Sets
idDef Guid -- PK to the type definition table
Value sql_variant
In fact it's a it more complicated (deep) due to list and list with property (2 more tables to store the value of a single user type value)
The problem is it's quite cumbersome to do a search for a value for example and we were thinking to store the data instead, in a table like that
Sets
id Guid
string1 nvarchar(max)
...
string15 nvarchar(max)
datetime1 datetimeoffset(7)
..
datetime15 datetimeoffset(7)
number1 decimal(8,2)
..
number15 decimal(8,2)
list1 uniqueidentifier
..
list15 uniqueidentifier
I'm not sure I explain my problem clearly but.. what I wonder is: is there a clever schema that will allow to store the untyped hierarchical user data, yet makes it easy to join / search, etc...
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hi,
If I understood you correctly, you have already created tables where you can handle dynamic amount of attributes and values. Querying such tables is often a bit tricky if you have several levels etc, but CTE[^] is a helpful tool when handling dynamic hierarchies.
On the other hand another possibility could be to use XML data type. This would allow you flatten the relational hierarchy and still be able to use highly dynamic values.
|
|
|
|
|
Yeah, XML data type, someone mentioned that... Have to have a look, thanks!!
I though I knew about CTE already but.. didn't know ou can use them for recursive queries!!! mm... thanks (again!)!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
No problem
|
|
|
|