sql

Help with a t-sql query

Hi Based on the following table Path ---------------------- area1 area1\area2 area1\area2\area3 area1\area2\area3\area4 area1\area2\area5 area1\area2\area6 area1\area7 Input to my stored procedure is areapath and no.of children (indicates the depth that needs to considered from the input areapath) areapath=area1 children=2 Above sh...

Does ordering matter for fields in a SQL update?

It occurs to me that if you have fields dependent on each other in an update statement, I'm not sure that one can guarantee the ordering (or that one needs to!). As an example, say you had the following Update: UPDATE Table SET NewValue = OldValue, OldValue = NULL Would NewValue always update first, then OldValue be nullified? Or is...

Porting join from Oracle to Postgres

INSERT INTO MISSION_OBJECTIVE( MSN_INT_ID, MO_INT_ID, MO_MSN_CLASS_NM, MO_MSN_CLASS_CD, MO_MSN_TYPE, MO_PRIORITY, MO_COMMENT, MO_START_DT, MO_END_DT, ASP_AIRSPACE_NM, MO_OBJ_LOCATION, MO_ALO_LEG_ID, MO_ALO_ARRIVE_LOC) SELECT '1025', '1', 'AIRDROP', 'ADP', 'LAPES', NULL, COALESCE( NULL, ' '), TO_TIMESTAMP( '1002260900', 'YYMMDDHH24MI'), T...

regarding like query operator

Hi For the below data (well..there are many more nodes in the team foundation server table which i need to refer to..below is just a sample) Nodes ------------------------ \node1\node2\node3\ \node1\node2\node5\ \node1\node2\node3\node4\ \node1\node2\node3\node4\node5\ I was wondering if i can apply something like (below query does n...

How to find N Consecutive records in a table using SQL

Hi, I have the following Table definition with sample data. In the following table, Customer Product & Date are key fields Table One Customer Product Date SALE X A 01/01/2010 YES X A 02/01/2010 YES X A 03/01/2010 NO X A 04/01/2010 NO X ...

Select the latest record for each category linked available on an object

I have a tblMachineReports with the columns: Status(varchar),LogDate(datetime),Category(varchar), and MachineID(int). I want to retrieve the latest status update from each category for every machine, so in effect getting a snapshot of the latest statuses of all the machines unique to their MachineID. The table data would look like Cat...

Help to the way to write a query for the requirement

I need to write a SQL-Server query but I don't know how to solve. I have a table RealtimeData with data: Time | Value 4/29/2009 12:00:00 AM | 3672.0000 4/29/2009 12:01:00 AM | 3645.0000 4/29/2009 12:02:00 AM | 3677.0000 4/29/2009 12:03:00 AM | 3634.0000 4/29/2009 12:04:00 AM | 3676.0000 // ...

Query a range of date

Hello Guys, Im trying to query a sort of from - to date. e.g. 20-01-2010 to 20-02-2010. this should include the mentioned dates. i've tried the following queries but none works. select * from [tableName] where date >= '20-01-2010' AND date <= '20-02-2010' but the date where date is equal to 20-02-2010 does not show. i don'...

using a JOIN in an UPDATE in SQL

Hi, I'm having trouble formulating a legal statement to double the statuses of the suppliers (s) who have shipped (sp) more than 500 units. I've been trying: update s set s.status = s.status * 2 from s join sp on (sp.sno = s.sno) group by sno having sum(qty) > 500; however I'm getting this error from Mysql: ERROR 1064 (4200...

INNER JOIN vs LEFT JOIN performance in SQL Server

I've created SQL command that use INNER JOIN for 9 tables, anyway this command take a very long time (more than five minutes). So my folk suggest me to change INNER JOIN to LEFT JOIN because the performance of LEFT JOIN is better, at first time its despite what I know. After I changed, the speed of query is significantly improve. I want...

Updating a Foreign Key constraint with ON DELETE CASCADE not updating?

We've realised in our SQL Server 2005 DB that some Foreign Keys don't have the On Delete Cascade property set, which is giving us a couple of referential errors when we try and delete some records. Use the Management Studio I scripted the DROP and CREATESQL's, but it seems that the CREATE isn't working correctly. The DROP: USE [Footpr...

round a number in SQL

I have a number and I use ROUND() function in SQL : SELECT ROUND(1.81999,2,1) I want the result 1.82, not 1.81. I don't know where my mistake is. ...

Selecting random top 3 listings per shop for a range of active advertising shops

I’m trying to display a list of shops each with 3 random items from their shop, if they have 3 or more listings, that are actively advertising. I have 3 tables: one for the shops – “Shops”, one for the listings – “Listings” and one that tracks active advertisers – “AdShops”. Using the below statement, the listings returned are random ho...

SQL Alias as Table.column

hi, is it possible to alias an aggregate function in a select clause as AliasTable.AliasColumn? The reason is because I want minimum modifications in my arrays (I'm using PHP). Thanks! P.S. I'm using SQl Server 2008 P.S.#2 Example: SELECT MAX(Person.name) name, MAX(Person.address) address, Farm.id, FROM Farm LEFT JOIN Person on Person....

Difference between sql, pl/sql and sqlj

I want to know how do the 3 compare with one another? which one to use when? which can be used as a replacement of other? ...

MySQL - Finding time overlaps

Hi, I have 2 tables in the database with the following attributes: Booking ======= booking_id booking_start booking_end resource_booked =============== booking_id resource_id The second table is an associative entity between "Booking" and "Resource" (i.e., 1 booking can contain many resources). Attributes booking_start and booking_en...

Would you use one or two tables for username and password?

Is it any safer to create a table holding user information and another one for their passwords than using the same table for everything? ...

System.Data.Common.DbDataReader

If I use this class to do a SELECT * FROM ... statement against a database, what method or variable of this class should I use just to give me a dump of the output from the SQL statement? ...

Problem in sql query

Hi I have 2 tables Order and orderDetails table... I have written a inner join SELECT Order.id FROM Order INNER JOIN orderDetails ON Order.id=orderDetails.id I have got the output as id 100 100 100 101 101 from the above data i want the count of each record OUTPUT AS : id count 100 3 101 2 he...

How can I exit an inner loop and continue an outer loop?

This is a follow-up to my previous question (Thanks for the answer, BTW!) If I have two loops: while @@fetch_status=0 begin set y=y+1 set x=0 while @@fetch_status=0 begin x=y+1 if y = 5 'exit the second do while and back to the first do while --> y=y+1 end end ...how can I exit from the...