sql

Using AVG() function between two tables

I have two tables, and I need to determine the company that offers the highest average salary for any position. My tables are as follows: employer eID (primary key), eName, location position eID (primary key), pName (primary key), salary) The code I wrote determines all avg salaries that are higher than one, but I need to find only ...

Is it possible to Update/Save new Record on databaseA on ServerA when databaseB on ServerB is updated?

I have this requirement that i need to Update/Save all records from DatabaseA on ServerA when DatabaseB on ServerB Status is updated to FG-FRESH. Example: ServerB| DatabaseB SerialNumber Status 0000001 Completed 0000002 FG-FRESH 0000003 FG-FRESH ServerA | DatabaseA SerialNumber Status 0000002 FG-FRESH 0000003 ...

sql recursive function - to find managers

Lets say I have the following table User_ID Manager_ID --------------------- Linda Jacob Mark Linda Kevin Linda Steve Mark John Kevin Basically the requirement is to pull all the managers under the user_id you are searching for. So for instance if I send in 'Linda' then it should retur...

SQL statement to get all customers with no orders

I have a typical Persons table and an Orders table defined in such a way that I can do JOIN query as the following to return Orders for all Persons. SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons INNER JOIN Orders ON Persons.id=Orders.Person_id The question is, how do I write a statement that would return all ...

Simple SQL Problem

Hey...I am in a bind here. I am not much of a programmer but the guy who does the sql at my business is out sick. If I have a table like this (I am simplifying this a lot but this is where I am stuck). Name Object Payment Joe A 100 Jan A 200 Joe A 300 Ron A 500 Jan A 100 Joe B ...

Does adding a unique constraint slow down things?

I have three columns in my table. +-----------+-----------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-----------------------+------+-----+---------+-------+ | hash | mediumint(8) unsigned | NO | PRI | 0 | | | nums | int(10) unsi...

sql - insert into multiple tables in one query

assuming that i have two tables, names and phones and i want to insert data from some input to the tables, in one query- How can it be done? Please, if it can be done, explain the syntax. ...

SQL question for e-mail thread view

I would like to query back a list of threads, with each of the conversation showing the latest message max(date), and a count of how many messages in the conversation count(*), group by threadID. Here's the SQL table Message ------------- messageID (int) subject (varchar) ... date (date) threadID (guid) How do I produce the following...

Oracle SQL Where clause to find date records older than 30 days

I want to find records in a (Oracle SQL) table using the creation date field where records are older than 30 days. It would be nice to find records using a operators like > but if anyone can suggest quick SQL where clause statement to find records older than 30 days that would be nice. Please suggest Oracle syntax as that is what I am us...

store commas in mysql database

Hello all, I'm trying to store the date in an sql table, but I want it formatted as such: Month day, year October 10, 2010 But whenever I do the sql call, the 2010 gets lost. How can I fix this? $eventdate = "October 10, 2010"; $sql = "INSERT INTO `tims`.`blog` ( `title`, `date`, `post`, `author`, `approved`) \n" . "VALUES...

Need advice to debug: SQL query to oracle using ADOdb taking way too long

I'm accessing a view table with 6 million lines from a oracle database using the ADOdb for PHP library. running the following SQL query from a web server in a SUSE machine takes about 1 min: $adodb_handle->Execute("SELECT COUNT(BEPROTEXT) FROM (SELECT BEPROTEXT FROM V_E_LOG WHERE BEPROTEXT LIKE '%jaya%' )"); running the same SQL...

SQL update top1 row query

The query below is working: update top(1) ShipBillInfo set shipfirstname='kkk' where CustomerId='134'; but it is showing error if i try to order by some Id: for example: update top(1) ShipBillInfo set shipfirstname='kkk' where CustomerId='134' order by OredrGUID desc; ...

Parallel processing in oracle

I had a 'procedure A' in which it has to return a null cursor to front end and then immediately it should continue with the next step in which it will call a procedure which will take 20 min to complete the proc. Procedure A(cur_out refcursor) begin OPEN cur_out for select null empname, null empid from dual; procedure B();//Wil...

Nhibernate mapping of System.Drawing.Image

Question: I get an exception serializing this class to a nHibernate xml file ({"Could not determine type for: System.Drawing.Image, System.Drawing, for columns: NHibernate.Mapping.Column(Settings)"}). How to map System.Drawing.Image to nHibernate ? And what MS-SQL dbtype is to be used? using System; using System.Collections.Generic; us...

From ImageHandler into flash

Hi Everyone, please help me.. i want to create flash file, that will load images from microsoft SQL server 2008. i am using ImageRequestHandler.ashx to get images from database and pass it into flash. ImageRequestHandler.ashx file public class ImageRequestHandler : IHttpHandler { public void ProcessRequest(HttpContext...

Calculate Distinct count when joining two tables.

id1 id2 year State Gender ==== ====== ====== ===== ======= 1 A 2008 ca M 1 B 2008 ca M 3 A 2009 ny F 3 A 2008 ny F 4 A 2009 tx F select state, gender, [year], count (distinct(cast(id1 as varchar(10)) + i...

Can a DBA find performance issues just from reading the TSQL code?

Can a DBA find performance issues just from reading TSQL code? Is a DBA expected to have that capability? ...

What are the benefits of using database cursor?

It is based on the interview question that I faced. Very short definition can be It can be used to manipulate the rows returned by a query. Besides the use of the cursor (Points are listed here on MSDN), I have a question in my mind that if we can perform all the operations using query or stored procedure (if I'm not wrong, Like...

Calling sproc from LINQ with an xml parameter

There is an existing sproc that for the purposes of this experiment I do not want to change. It is currently called via a non-linq method like a sqlcommand and takes an xml parameter. Current implementation (Non-Linq) An xml fragment eg: "<someTag>1</someTag><someTag>2</someTag>" is passed to the sproc as a string. Notice that ...

Can we rollback to original state after we have used DBCC CHECKIDENT to restart Identity column count ?

Currently on some operations I have to delete the old data and insert new one. But I noticed that inspite of deleting data the identity column did not reset and continued from its last max value. So i used the DBCC CheckIdent for achieve the same all this is taking place within a trasaction. Can i rollback the transaction back to the int...