sql

How do I use SQL to select rows that have > 50 related rows in another table?

I've been trying to find out how to write this query in sql. What I need is to find the productnames (in the products table) that have 50 or more orders (which are in the order table). only one orderid is matched up to a productname at a time so when I try to count the orderid's it counts all of them. I can get distinct productn...

SQL Server query help... need to convert varchar to date

Hi All, I am writing a query to fetch results for all the values in a column which is of varchar type.. are less than '29/08/2010' (date) My Query: SELECT * FROM EMPLOYEES WHERE COLUMN1 < '29/08/2010' Here the column1 is of varchar type. I am using SQL Server 2005 Is there a way to make this possible..?? Pls help me. Thanks in ad...

How to call a procedure or fire a trigger when a new connection is established in SQL Server 2008

Hi i want to call a stored procedure or fire a trigger when a new connection is established in SQL Server 2008. Thanks ...

How to get rightmost 10 places of a string in oracle

Hi, i am trying to fetch an id from an oracle table. Its something like "TN0001234567890345". What i want is to sort the values according to the right most 10 positions. I am using oracle 11g. Is there any funcrion to cut the rightmost 10 places in oracle ? thanks in advance tismon ...

Store Open/Close Times and DST Changes

I've been stuck on this for two days and have gotten no where. I tend to think future and the future problems that will come around. My server's time is set to UTC and linux box is fully updated with the timezones as well as the data is in my database. I'll explain my system for the best answer. This site sells "items" but can only s...

How to write SQL query for aggregate total value for a particular condition

vote table PK_ID ob_type ob_id VOTE user_id VOTED_ON 1 100 1 1 NISHANT 02/08/10 2 100 1 1 DEVI 02/08/10 3 100 1 1 VIRENDRA 02/08/10 4 100 1 0 XYZ 02/08/10 5 200 1 1 XCXCX 02/08/10 6 200 1...

Delete duplicated rows from database

I need to delete duplicated rows from database. Can i do it with simple sql query? If not, please, show me some quick algorythm to do it. Example: id| field_one | field_two | 1 | 0000000 | 11111111 | 2 | 2222222 | 33333333 | 3 | 2222222 | 33333333 | 4 | 4444444 | 55555555 | I need to delete row with id 2 (or 3, no matter,...

SQL: get the place in results query

I have a table called 'points' that has a field 'total' which contains the total points for a record. Now I would like to calculate the rank of a specific record. So like: SELECT (...) as rank FROM points WHERE id=63 Is this possible in SQL? ...

SQL Finding Orders belonging to a product category

Im trying to find all orders in the database where the product belongs to a product category. But the category is stored in the Orderline table. My table structure is roughly: Order Table ID Date OrderLine Table ID Product_ID ProductCategory_ID Quantity Product Category Table ID Name My sql looks like: Select o.Id, o.Da...

Select top record from group

How to from this table Name Code ABC Code1 DEF Code1 GHI Code2 JKL Code2 OMN Code3 get this result: Name Code ABC Code1 GHI Code2 OMN Code3 Is there any simple solution? ...

how to make a join statement between multi table to one table?

First, i have 4 table and columns such as feeds (id, type, type_id) feeds_normals (id, type, content) feeds_links (id, type, title, link) feeds_youtubes (id, type, title, link, description, image) feeds_photos (id, type, link) The table of "feeds type_id" is match/linkup "id" of normals, links, youtubes, photos And The table of "...

SQL generalization/specialization, data redundancy

I have three tables: actions, messages, likes. It defines inheritance, messages and likes are actions' childs (specialization). Message and Like both have column userId and createdAt. Those should be of course moved to the parrent table Action and removed from Message and Likes. But there's only one case when I need to select both messa...

TSQL Trim - Portable Method

I have a string in the following format 'DOMAIN\username'. I wish to trim the domain and the backslash from the string. I cannont simply use RIGHT() as we have multiple domains of varying length. What is the most portable way to do this? Thank you. ...

help in sql command .. i want list names which have defined id s.......

hello i have table consist of columns : id,name,job and i have row stored with this data : id: 1 name : jason job: 11,12 id: 2 name : mark job: 11,14 i want write sql command to fetch names which have value "14" stored in job column only from this table so how i do that ? thanks ...

Modify table: not null to null

How to change one attribute in a table using T-SQL to allow nulls (not null --> null)? Alter table maybe? ...

Generate List of Week Number + Start Date + EndDate against any year using SQl Querry

Hi, I want to generate a temp table having following columns: WeekNO StartDate EndDate using an UDF having a year parameter (YEAR(YYYY)). ...

How do I update my SQL database using XML?

I have the following XML file: <?xml version="1.0" encoding="utf-8"?> <Patients> <Patient EMail="[email protected]"> <FirstName>LeBron</FirstName> <LastName>James</LastName> </Patient> <Patient EMail="[email protected]"> <FirstName>Kobe</FirstName> <LastName>Bryant</LastName> </Patient> <Patient EMail="Allen@Ivers...

speeding up outer join query for newsletter script

Hi, I've got a PHP script that sends newsletters to a bunch of email adresses, it sends 15000 newsletters an hour, until all email adresses have been processed. Because this process isn't run in one time, I have a table where I register all the adresses which have been mailed, so I can always easily get the unmailed adresses. Here is...

Like SQL Query in LINQ

Hi, My problem is the following: I'm looking for a solution in LINQ which translates a LINQ expression to SQL LIKE query. (I know in LINQ I can use Contains, StarsWidth, EndWidth instead of 'LIKE' but in my case is not a good solution, and if you check the generated sql script you will see it is not use LIKE) I found a lot of article...

Updating lonvar columns in sqlbase database via .net

I need to put the item-id of a newly created appointment into a table. The Database is Unify Sqlbase and i use their .net data provider to access it. My code goes as follow: ItemId newAppointmentID = user.ExchangeConnection.createAppointment(subtype, text, finalDateVor, finalDateNach); SQLBaseCommand writeComm = sqlbaseConnection.Crea...