sql

Parent Child table record - Building SQL query

Here is my table and data of these tables Table name: Code CID Code 1 abc 2 def 3 xyz Table Name : Details ID Date Value1 CID 1 1/1/2009 12 1 2 1/1/2009 25 2 3 1/1/2009 18 3 4 1/2/2009 36 1 5 1/2/2009 45 2 6 1/3/2009 19 1 Resulta...

SELECT INTO the same table

I have a requirement where I want to rename a column. In in this case, it should happen like: 1.) I need to create a new column with the existing column structure. 2.) Migrate the data to the new column. 3.) Retain the old column. I don't have the new column structure and I have to take it from the old column. TIA. ...

Optimize pass parameter to view

I have quite complicated view in mysql, like select filter.id as filter_id, person.id, person.name from person, filter inner join ... left join ... where person_match_filter_condition ... group by filter.filter_id, person.id, person.name Query filters person which corresponds domain specific conditions. Typical use of view is: sel...

C# binary array to decimal ?

In SQL, the following works cast([comlum] as Decimal(18,4)) How can I do the same conversion (from the binary data) in C#? the data type of varbinary in SQL C# loading to byte[] so, I want to byte[] convert to decimal or double? Sql query: select cast([column_A] as decimal(18,4), [column_A] from table result: 191128.0000      0x120...

How to sort rows in a table and fetch row positions?

Consider the following table structure: id name rank position ------------------------------- 1 Steve 5 0 2 David 3 0 3 Helen 9 0 4 Mark 15 0 I need a fast algorithm to rate these rows by rank column and store the "position" of each row in position field in realtime. ...

Find time duration

I have two date fields with times.They are 1.2008-06-09 10:18:00.000 2.2008-06-10 11:20:00.000 I have to find the difference between the above two dates in the format - "24 hour:2 minutes:0 seconds" Is there any method to get this result in sql 2000? ...

how can i change enterprise library connection state

Hi there, I am using Microsoft Enterprise Library for MS SQL. Enterprise Library automatically closes its connection, but I don't want it to close. How can I keep open an Enterprise Library Connection? Thanks a lot.. ...

How to make a user function deterministic

I'm trying to achieve optimization based on deterministic behavior of a user defined function in SQL Server 2008. In my test code, i'm expecting no extra function calls dbo.expensive, since it's deterministic and called with same argument value. My concept does not work, please explain why. What could be done to achieve the expected op...

How to render in a user defined sort order?

We have a requirement to retreive books in a user defined order (e.g. Assuming there are 3 books - BookA, BookB, BookC), its possible that an end user would like to see this rendered as (BookB, BookA, BookC) or (BookC, BookA, BookB). We are thinking of adding a integer column (e.g. sortColumn) to capture this order. Is this a good opt...

MySQL: Avarge and join two querries

I have two queries: SELECT s.id AS id, g.id AS group_id, g.nazwa AS group_name, s.nazwa AS station_name, s.szerokosc AS szerokosc, s.dlugosc AS dlugosc, s.95 as p95, s.98 as p98, s.Diesel as diesel, s.DieselTIR as dieseltir, s.Super98 as s98, s.SuperDiesel as sdiesel, s.LPG as lpg, s.ulica as ulica, s.kodP...

How to fetch records form three table

Table Name :: Feedback_master Fields 1. feed_id 2. roll_id 3. batch_id 4. sem_id (semester ID) 5.f_id (faculty Id) 6. sub_id (subject Id) 7. remark. 8. b_id Table Name :: subject_master Fields sub_id (subject Id) sub_name (Subject Name0 f_id ( Faculty ID) Table Name :: faculty_master Fields f_id (Faculty Id) f_name (Faculty Na...

SQL Server 2005, bulk UPDATE or INSERT

Hello, I'm looking for a solution to perform Insert, on duplicate key Update like operation in SQL Server 2005. This operation might Insert or Update large number of entries. SQL Server 2008 has a neat operation MERGE which would do it perfectly, the problem is we're stuck with SQL Server 2005. I've looked into standard solutions, but a...

Why is it recommended to avoid unidirectional one-to-many association on a foreign key?

In the Hibernate online documentation, under section 7.2.3 One-to-many, it's mentioned, that: unidirectional one-to-many association on a foreign key is an unusual case, and is not recommended. You should instead use a join table for this kind of association. I would like to know why? The only thing that comes to my mind is...

Regarding SQL Server Locking Mechanism

Dear GURUs I would like to ask couple of questions regarding SQL Server Locking mechanism If i am not using the lock hint with SQL Statement, SQL Server uses PAGELOCK hint by default. am I right??? If yes then why? may be its due to the factor of managing too many locks this is the only thing i took as drawback but please let me know ...

Return first 100 letters from database field?

In my database MYDB i have a table called MYTABLE and inside it I have a column called NAME. I want to only return the first 100 characters of the column NAME. (NAME can be up to 2000 characters). How can this be done in SQL as I want to set the first 100 characters to a ASP.NET label. Thanks in advanced! ...

Return value from database without the HTML tags?

In my database MYDB I have a table called MYTABLE and I have a column called Description. I am saving a long description in there with multiple HTML tags. How can i return the values and not include all the HTML tags? Is this even possible? What will be the best way of doing this? In the SQL statement or in code behind? And how will I ...

How are logical reads calculated ?

I've read the definition of logical reads from: http://msdn.microsoft.com/en-us/library/ms184361.aspx it says: "Number of pages read from the data cache." I have two tables (Row count of table_1 is 141, and table_2 is 16.811), when I run those two queries, it gives the following result. SELECT * FROM Table_1 results Scan count 1, ...

Order by in SQL

Is it possible to order a query result based on 2 columns with the first sorting ascending on column1 and the secondary sort on column2 in desc? select * from table1 orderby column1, column2 I believe this SQL statement should work, would adding desc along with the second column work or is there any better way of doing it? ...

Is there any tool/SW to help me build a good database ?

I am new to databases. I have a classifieds website with MySQL db and I am soon about to use SOLR to index them also. Then whenever a query is done, SOLR will return ID:s and I will match those ID:s to the MySQL database and fetch the ads to display. Anyways, I have trouble making the db. Users may choose from a drop-list what category...

How to compare two SQLite databases on Linux

Using Linux, I want to compare two SQLite databases that have the same schema. There will be just a few differences. Is there a tool that would output these differences? Preferably output them to the command line, so that I can grep/sed them. SQLite uses SQL, so a general SQL tool might also do. ...