|
Hi Folks,
I have a database table named Voyage_History that stores the voyage information of our company's vehicles. I have imported data from an MS Excel file and finally I had get the result as screen below:
---------------------------------------
SELECT Voyage_ID,PlateNumber,StartDate from Voyage_End as ddd
Group By Voyage_ID,PlateNumber,StartDate
Voyage_ID PlateNumber StartDate
----------- ----------- ------------------------------------------------------
1 34 DD 0254 2005-12-28 00:00:00
2 34 DD 0254 2005-12-28 00:00:00
3 34 DD 0254 2005-12-30 00:00:00
4 34 DD 0254 2005-12-31 00:00:00
5 34 DD 0254 2006-01-01 00:00:00
6 34 DD 0254 2006-01-04 00:00:00
7 34 DD 0254 2006-01-05 00:00:00
8 34 DD 0254 2006-01-05 00:00:00
9 34 DD 0254 2006-01-06 00:00:00
10 34 DD 0254 2006-01-06 00:00:00
11 34 DD 0254 2006-01-12 00:00:00
12 34 DD 0254 2006-01-13 00:00:00
13 34 DD 0254 2006-01-16 00:00:00
14 34 DD 0254 2006-01-17 00:00:00
15 34 DD 0254 2006-01-17 00:00:00
16 34 DD 0254 2006-01-21 00:00:00
17 34 DD 0254 2006-01-23 00:00:00
18 34 DD 0254 2006-01-26 00:00:00
------------------------------------------------
In fact, voyage_ID 1 and Voyage_ID 2 are same voyages. Because all data is same.
How can I create another table that stores unique Voyage_ID, and the most important part of the question how can I import this data correctly? ( I mean how to determine the same voyages)
Should I have apply a recursive select statement?
-- modified at 9:44 Thursday 13th July, 2006
|
|
|
|
|
This will give you all duplicates:
SELECT a.*
FROM Voyage_End a, Voyage_End b
WHERE a.Voyage_ID != b.Voyage_ID AND a.platenumber = b.platenumber AND a.startdate = b.startdate
But you could use something like this to insert into your table:
SELECT (SELECT TOP 1 voyage_id
FROM Voyage_End a where a.platenumber = b.platenumber and a.startdate = b.startdate) as voyage_id, PlateNumber,StartDate
FROM Voyage_End b GROUP BY platenumber, startdate
Or, if you don't care about the IDs, then just:
insert into voyage_end2 (platenumber, startdate) select distinct platenumber, startdate from Voyage_End
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Wow...really good results...
Is it possible to move a column from second row to first row? I mean suppose that I made a basic select operation and got the result as below:
---------------------------------------------------------
SELECT Voyage_ID,StartDate,PlateNumber,Driver1 FROM voyage_END
order by startdate
Voyage_ID StartDate PlateNumber Driver1
421 2005-12-28 34 VS 0845 X
750 2005-12-28 34 VS 0845 Y
----------------------------------------------------------------
The MAJOR problem is:
How can I create a new table such as:
Voyage_ID StartDate PlateNumber Driver1 Driver2
421 2005-12-28 34 VS 0845 X Y
difficult case...right?
|
|
|
|
|
I don't understand the question.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Wow...really good results...
Is it possible to move a column from second row to first row? I mean suppose that I made a basic select operation and got the result as below:
---------------------------------------------------------
SELECT Voyage_ID,StartDate,PlateNumber,Driver1 FROM voyage_END
order by startdate
Voyage_ID StartDate PlateNumber Driver1
421 2005-12-28 34 VS 0845 X
750 2005-12-28 34 VS 0845 Y
----------------------------------------------------------------
The MAJOR problem is:
How can I create a new table such as:
Voyage_ID StartDate PlateNumber Driver1 Driver2
421 2005-12-28 34 VS 0845 X Y
difficult case...right?
|
|
|
|
|
Would be to have driver in another table since there is an obvious 1 to many relationship between the data. However, you can write a T-SQL cursor to loop (I know, I know I am laughing as I type) through the data and create a mock data set that matches your hearts desire. It will be slow though. Split the tables make your life easy.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
This isn't very pretty...and there are probably better ways to do what you want. But, if there is only ever two drivers, you can still get it all into another table with just one SQL:
insert into voyage_end2 (voyage_id,platenumber, startdate,Driver1,Driver2)
SELECT (SELECT TOP 1 voyage_id
FROM Voyage_End a where a.platenumber = b.platenumber and a.startdate = b.startdate) as voyage_id,
PlateNumber,StartDate,
(SELECT TOP 1 Driver1
FROM Voyage_End a where a.platenumber = b.platenumber and a.startdate = b.startdate order by Driver1) as Driver1,
(SELECT TOP 1 Driver1
FROM Voyage_End a where a.platenumber = b.platenumber and a.startdate = b.startdate and
(SELECT TOP 1 Driver1 FROM Voyage_End a where a.platenumber = b.platenumber and a.startdate = b.startdate order by Driver1) != Driver1 order by Driver1 desc) as Driver2
FROM Voyage_End b
GROUP BY platenumber, startdate
However, your best long term solution is to do as Ennis Ray Lynch, Jr. has suggested and modify your table structure.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Hi,
I want to do a transactional replication for a SQL database using c# code; can anyone please help me to do so ?
Of course any code on any language would do the the job for me, as I can change it to c#.
I think the best way is making use of SQLDMO, although I've got no idea on how to do it.
Thanks
farshad
|
|
|
|
|
I have web application use Database is SQLServer 2000
every day have 10000 people visit my Web site
and Size File Log increase very higth but my server end space
can i use add new database server
Some body help me
|
|
|
|
|
Can you calrify, You are talking about database log file or any extra log file like texxt file on the server to record log.
Kumar Prabhakar
|
|
|
|
|
yes when many people visit and many query to database get Data
so file Log of Database very big
|
|
|
|
|
This growing of the log-file will stop if you backup it regularly.
Or you can change the recovery model to Simple.
Wout Louwers
|
|
|
|
|
You're not backing up your transaction log. SQL Server maintains a record of all transactions within the log to enable you to restore to any point in time.
See this comment[^] of mine on someone else's similar problem.
See also here[^] for more about what the transaction log contains.
Stability. What an interesting concept. -- Chris Maunder
-- modified at 9:19 Thursday 13th July, 2006
|
|
|
|
|
FYI:
I'm programming in Visual Basic 6.0
I have an ADODC control that is linked to a .mdb file I created in Microsoft Access
The provider I am using to connect to the database is Microsoft Jet OLE DB 4.0
My Problem:
String comparisons in my SQL queries are not behaving the way I'd like:
As a silly example,
SELECT * FROM tbl WHERE 'a' = 'A' returns everything in tbl
SELECT * FROM tbl WHERE 'a' > 'A' returns nothing in tbl
SELECT * FROM tbl WHERE 'a' < 'A' returns nothing in tbl
How do I make the above comparisons so they are case sensitive?
I need my comparisons to abide by the following character ranking scheme:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoffpro01/html/GettingStartedwithADO.asp
Under this scheme, the following holds:
('a' = 'A') = FALSE
('a' > 'A') = TRUE
('.0000m3d10_1' > '.0000m3d10Z') = TRUE
Your help is greatly appreciated!
-Lee``
|
|
|
|
|
I think you'll probably find that an Access DB is not case sensitive (for indexes and data) and i don't believe you can get it to be either. Why not try SQL Server 2005 Express edition instead as you will be able to set the database up with a binary or case sensitive sort order (i.e. There will be case sensitivity for strings)
You can do it in code though in access check this out here for more information.
-= Technomancer =-
-- modified at 0:09 Thursday 13th July, 2006
|
|
|
|
|
hi
Access databases in spite of tables have queries stored in them. i wanted to know do other Databases (oracle,sqlserver,..) have Queries stored in them. if so, how should i get their names or their SQL statement?
is there something in databases's SCHEMAINFORMATION for this?
|
|
|
|
|
I'm familiar with SQL Server 2000. They don't have "queries" but they have stored procedures in which you can create queries, and return results.
For example, my datagrid calls a stored procedure that looks up the information about a part, based on what the user entered as a part number.
If you have Enterprise Manager installed onto your computer, you can connect to the server, then the database. Inside the database you can look at the tables, stored procedures, users, etc. Without EM I am not sure how else to look at them unless you are on the server directly.
Hope that helps.
|
|
|
|
|
SQL Server has "Views" that are comparable to the MS Access query.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
thanks leckey for answering
yeah i think thats something like stored procedures.
i want to do that programmatictly. i want to get their names and then use those names to retrieve the SQL statement and then execute that statement.
|
|
|
|
|
SQL Server:
select * from INFORMATION_SCHEMA.VIEWS
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
|
If information_schema is supported:
Stored Procedure Names
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
Stored Procedure Definition
SELECT ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES
View Names
SELECT VIEW_NAME FROM INFORMATION_SCHEMA.VIEWS
View Definition
SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS
With SQL Server (the only thing I have to test on right now) the definitions are not just the query, but the entire definition, including the 'CREATE PROC' or 'CREATE VIEW' part of the definition. Also stored procedures often have a lot of programming in them and can be quite long.
-- modified at 12:26 Thursday 13th July, 2006
|
|
|
|
|
hi
i wamted to know how to update my data source through a DataGrid.
i have a DataTable and i bind it to a DataGrid.
when user changes the data in the datagrid the data in datatable also change.now I want to apply this change to my database file. I used DataAdapter's Update method but it gives exception. what should i do?
|
|
|
|
|
There is an 18 part series on DataGrids at
http://aspnet.4guysfromrolla.com
I'm not sure which part is the one your looking for, but I've found it very helpful.
Also, you may want to post your actual code and highlight what row you are getting the error.
|
|
|
|
|
in:
mydataadapter.Update( mytable );
the table is that bound to datagrid and changed. i want my database to change too.
|
|
|
|