sql

How can I not display null values in left join results?

Hello everyone: I have a query that works well, but I'm trying to see if I can clean up my results a little bit. The query pulls the State and Fiber ID fields from my table called fiber_intake. It then pulls all fields from my hvi table where the Fiber ID = GA in the fiber_intake table. Code: SELECT `fiber_intake`.`State`, `fiber_int...

Sum up the aggregrate in SQL Server or ORACLE

I am running the query below and need to include a total at the bottom but not sure how to run it in SQL SERVER. (I can copy the data and do an auto sum in Excel but it's a bit repeatative) Could some one please help? SELECT LOCATION, SUM(CASE WHEN my_date >= '10/1/2009' AND my_date <'01/01/2010' THEN QTY ELSE NULL END) AS QTR1, SU...

updating fields automatically

hi im new to programming i have this small system for room reservations (school requirement). i have this question that is it possible to update the fields of my table on specific date? i have three tables naming users , reservations, and rooms. i want to update the field of the rooms on specific date, like if the date_out in the rooms ...

TSQL, counting pairs of values in a table.

Given a table in the format of ID Forename Surname 1 John Doe 2 Jane Doe 3 Bob Smith 4 John Doe How would you go about getting the output Forename Surname Count John Doe 2 Jane Doe 1 Bob Smith 1 For a single column I would just use count, but am unsure ...

Setting IsPrimaryKey=true on column in table with no primary key

Hi, I'm writing a quick app using LINQ to SQL to populate a db with some test data and had a problem because one of the tables had no primary key as described by this bloke Can't Update because table has no primary key. Taking the top answer I added the IsPrimaryKey attribute to an appropriate column and the app worked even though the...

Recursive CTE to find parent records

Hello, first i must admit that i'm not very familiar with sql server's recursive CTE's but i think this is the best approach. I have a table tabData. Its PK is named idData and there is a self referencing FK fiData. So fiData references the parent record and SELECT * FROM tabData WHERE idData=fiData returns all data of the parent. T...

selecting more than one row of matching data

Hi, I need to select the number (cid) of a customer that has rented the same movie from 2 different branches. My tables are as follows: RENTED (cid, copyid) 12345 99999 12345 88888 COPY (copyid, mid, bid) 99999 444 123 88888 444 456 So one customer (12345) has rented the same move (444) from two different branches (123, 45...

Precedence of operators in SQL*Plus

How is A - B U B - A parsed in SQL*Plus? Is it parsed as (A - B) U (B - A) or as A - (B U B) - A ? I could find this page using Google, but it doesn't say which has higher precedence, U or -. ...

How to query column history from a "memo" field in Access 2007?

Trying to construct a query in Access 2007. One of the columns has the data type "Memo". Sometimes the latest version is returned and for others the display is blank. Only if I right-click and select "Show column history" on each row, can I actually see the full set of data in this column. Is there a way through the query designer or...

I need to create an ashx httphandler to display images from SQL Server 2008 using SQL FILESTREAM

Hi Guys, I'm trying to create an ashx httphandler to display images from SQL Server 2008 using SQL FILESTREAM. Does anyone have an example of the web.config setting and ashx code needed to do this? Thanks! Richard. ...

COALESCE vs IS NOT NULL performance on checking empty string

Some articles I found on the internet compared ISNULL with COALESCE, so I think my question is a little different. I'm wondering which is better in terms of performance? SELECT * FROM mytable WHERE mycolumn IS NOT NULL AND mycolumn <> ''; Or SELECT * FROM mytable WHERE COALESCE(mycolumn,'') <> ''; Other than performance, are there...

MySQL: JOIN two tables on LIKE

I have a table with a column containing text, and I want to select all of the tables where the text from one of the rows in a second table appears in that row. Here is a pseudo-query: SELECT title FROM recipes AS r JOIN ingredients AS i ON r.ingredients LIKE '%' + i.name + '%'; The above query does not work, however. How do I ...

SQL: Need to return specific dates for sku's

Here is what i have: UPDATE webdev.tempdb.dbo.MediaResource SET Date_Min_Enabled = PRAH.DateCreated FROM FeedBack.dbo.Part_Resource_Associations_History as PRAH JOIN WebDev.DataWareHouse.dbo.Inventory as I on I.SKU = PRAH.PartNumber JOIN FeedBack.dbo.Part_Resource_Associations as PRA on PRA.PartNumber = I.SKU This only return...

SQL string match numbers, varying length

I am looking up which exchange services which telephone numbers, from a table of fragmentary numbers that show which exchange services them. So my table contains, for example: id |exchcode |exchname |easting|northin|leadin | ----------------------------------------------------------------- 12122 |SNL/UC |SANDAL ...

Mysql: Date as string

I have a field in MySQL as varchar and need to do a select with a range. The date is in the following format "%m/%d/%Y" (Ej. 10/14/2010). ...

mysql Creating a temporary table not working...undeclared variable error...whats wrong with my code?

When I run the code below inside phpmyadmin I get an error "Undefined Variable tmpportfolio" what is the problem? SQL: CREATE TEMPORARY TABLE tmpportfolio (p_name VARCHAR(255),portfolio_id INT UNSIGNED NOT NULL); SELECT p_name, portfolio_id INTO tmpportfolio FROM portfolio WHERE parent_portfolio_id IS NULL AND portfolio_i...

SQL multiple join with count, having trouble.

Hello All, First of all this is a homework assignment so I'm looking for assistance, not solutions. Let me try to explain my schema. I have three tables we'll call users (with columns id and name), parties (with columns id, partydate, and user_id) and questions (with columns id, createdate, and user_id). My requirement is to show for e...

Access SqlCeDB with relative path to sdf on VS2010

I have a SqlCeDB as part of my project, right now the connection string is the following: public String localDBConnectionString = @"C:\Users\Patrick\Documents\Visual Studio 2010\Projects\WpfApplication1\WpfApplication1\MapProjectDB.sdf"; Obviously this is going to fail when I publish it and put it on another machine. How can I make t...

How to add surrogate key to related tables?

I need to add a auto-inc surrogate key to three tables in my data warehouse: Note: These are not the real table names JakMaster (JakMasterId, Date) (PK) Note: JakMasterId is varchar(60) JakToRoad (JakMasterId, Date) (FK) JakToBig (JakMasterId, Date) (FK) What steps should I take to add a surrogate key to these three tab...

Difference between varchar and varchar2 in SQL

What is the Difference between varchar and varchar2 in SQL. Please explain in detail with some good example. ...