sql

Problem using MySQL LOAD INFILE

hi, I have a products table with the following structure CREATE TABLE IF NOT EXISTS `products` ( `id` int(50) NOT NULL AUTO_INCREMENT, `productname` varchar(255) NOT NULL, `description` text NOT NULL, `merchanturl` text NOT NULL, `imageurl` text NOT NULL, `price` varchar(10) NOT NULL, `original` varchar(10) NOT NULL, ...

Access Nz() function doesn't work in query

I have lots of orders in tblOrders and a few deliveries in tblDeliveries. SELECT tblOrders.SkuBestelId, Sum(tblDeliveries.delivered) AS TotalDelivered FROM tblOrders INNER JOIN tblDeliveries ON tblOrders.SkuBestelId = tblDeliveries.SkuBestelId GROUP BY tblOrders .SkuBestelId; Of course, this gives me lots of "TotalDelivered" fields wi...

Generate a row in an aggregation query for a date with no results against it.

I'm sorry if the title question isn't very clear but i don't think i can expalain my problem in a single sentance. I have a table with a number of different types of events in it all recorded against a date. I'm querying the table and grouping based on a subset of the date (month and year). SELECT DATENAME(MONTH, event_date_time) + ' ...

Select date range using SQL

Hi everyone, I'm trying to select a date range using SQL and I've come across a few issues: When I run something along the lines of: SELECT ... as edate ... WHERE edate BETWEEN To_Date('10/15/2010', 'MM/DD/YYYY') AND To_Date('10/15/2011', 'MM/DD/YYYY') it will come back with a ORA-01848: not a valid month . The tab...

How to compare values for last and second last entry in table?

I have a table in Oracle called quotes with two columns: date and value. I would like to compare values for last entry and second last entry in the table. In this example I would like to get dates for 13.1 and 11.1 in one line and the difference between the values for each date (10-5=5). Quotes Table: Date - Value 13.1.2010...

(T-SQL) Check if a procedure exists before creating it.

I decided to edit my post since people didn't quite get what I'm trying to do (I suppose it was not irrelevant to say why I needed it after all): Ok, there we go. The thing is, I have a HUGE SQL script which many clients use and it has to be ran thoroughly every time a client executes the "database management" functionality that our sof...

TSQL Selecting 2 & 3 week intervals.

I am attempting to populate a table based on 2 and 3 week intervals for a semi-monthly pay period in TSQL. The table should populate, 2 week date 2 week date 3 week date 2 week date 2 week date 3 week date ..based on the first date I supply, subsequently adding 2 or 3 weeks to the last date supplied. I should be able to supply a star...

Does SQL have a list type that can be used in a WHERE ... IN clause?

Possible Duplicates: Parameterizing a SQL IN clause? SQL Server SP - Pass parameter for IN array list? I need to search for a haphazard set of integers on two different tables: SELECT col_1, col_2 FROM LIKES_NUMBERS WHERE col_1 IN (1,2,3,5,7,1021,10041411) SELECT col_one, col_two FROM LIKES_NAMES WHERE ...

Serial number issue in SQL Server 2008

Hello experts, I have orders and order details table as shown as below: OrderDetails Order_ID int Order_Code varchar(10) Product Name varchar(50) Qty Int SeqNO varchar(10) Below are the sample records 10001 OC Ottoman 10 Null 10002 OC Ottoman 3 Null 10003 OC Ottoman 2 Null 10004 OC Ottoman...

SQL Stored Procedure Styles in Visual Studio 2008 SQL editor

My question is pretty simple but I just couldn't find the setting to change this. I am using Visual Studio 2008 as my SQL stored procedure editor. After I switched to Window 7, the SQL style in VS2008 changed and is now all over the place compare with the styles I used to have in Window XP VS2008. It shouldn't be the Operating System pro...

Can an SQL stored procedure simply return its inputs, concatenated?

To fit an edge case, I'd like to create a stored procedure (Access SQL!) which simply returns the concatenation of three inputs. So MyProcedure('AAA','BBB','CCC') returning 'AAA,BBB,CCC' Obviously this is elementary in most programming languages, but I didn't know if SQL was capable of this at all. ...

SQL Query Producing No Results

Hello, I am trying to make this query work: SELECT Stock.*, StockFeatures.Features, StockDescriptions.Detailed, StockDescriptions.Technical, PRD1.RuleValue as Price, PRD2.RuleValue as WasPrice, PRD2.RuleValue-PRD1.RuleValue as Save, PRD1.Quantity FROM StockFeatures, Stock INNER JOI...

How to make full text query with AND when text spans several columns

We have table with several full text indexed fields. Say, it is firstName, surName and lastName. I'm looking for "John AND Smith" and obviously these two words most likely will be written in different fields. Query returns nothing. If I search for "John OR Smith" it is working. The question is: can I somehow tell SQL Server that all fie...

Cross DB SQL Trigger Epic Failure

I have the below SQL Trigger on a SQL 2005 box that is supposed to help me replicate certain Person Info to another database to be used for Reporting and various other things as a reference. I have 1 DB named Connect which is where the current app manipulates the Person Data on tblPerson. I have another DB, on same physical box, named ...

How do I use "group by" with three columns of data?

My query currently is: SELECT x, MAX(z) AS mz, y FROM my_table GROUP BY x The columns x and mz are returned as expected, but the last column, y, does not match up with the other two. In other words, I want the "y" column to match the mz column just like the x column currently does. How do I pull that off? UPDATE: Sorry, the question ...

OUTER JOIN using IN list?

I'd like to find the hits and misses in a table using only a list of items without having to create a new table to contain the list items and without using any scripting. I do many ad-hoc queries throughout the day so this would be useful. Here's an example of what I'm using now: SELECT custid, name, email FROM customers WHERE cust...

Searching for (freeware) database migration tool

Hello there! I'm searching for a tool to dump a database including DDL and content as plain SQL-SCript, so that in can be archived in plain text format. I know e.g. the Oracle dump tools or mysqldump, but is there a tool which can connect to different datasources and get the job done? GUI would be great. Thanks, Chris ...

Disable Constraints on Bulk Update in SQL Server

I need to change the values of a PK/FK (add 10000) on 2 tables. How do I tell the two tables involved that they should not care about referential integrity during the update, but to care after. I don't want to have to drop and recreate the relationships if I don’t have to. ...

Are these 2 sql queries equivalent in all respects (e.g. estimated and actual execution plan)?

Are query 1) == 2) in terms of estimated query plan AND actual plan? (can statistics affect the actual plan here, ever?) declare @cat int -- input param from prc ... 1) select * from A as a join B as b on b.id = a.id on b.cat = @cat join C as c on c.fid = b.fid on c.cat = @cat where a.cat = @cat 2) select ...

IDENTITY_INSERT in trigger

Is it possible to turn it on in a table trigger? I tried creating a trigger with SET IDENTITY_INSERT tableName ON But when I open the trigger definition, I see that the statement is not there.... This is my query to alter my trigger to add the IDENTITY_INSERT, when I open the definition, the IDENTITY_INSERT is removed ... SET ANSI_...