sql

How to search with multiple criteria from a database with SQL?

Hi. I am a newbie programmer. I have a page looks like below. I have a car database and i have to make a search from database with this page. There are many criterias that Users can enter and select values. But User doesn't have to fill or select all criterias. For example User can search a car that only depends on "Mark" or can search t...

sql charateristic function for avg dates

I have a query which I use to grab specific dates and a price for the date, but now I'd like to use something similar to grab the avg prices for particular days of the week. Here's my current query which works for specific dates to pull from a table called availables: SELECT rooms.name, rooms.roomtype, rooms.id, max(availables.updated_...

tsql function split string

I wonder if anyone can help me. I need a tsql function to split a given value such as: 1) 00 Not specified 3) 01-05 Global WM&BB | Operations 2) 02-05-01 Global WM&BB | Operations | Operations n/a I need to get a result like this: cat1 cat1descr cat2 cat2descr cat3 cat3descr ---------------------------------...

How to retrieve .NET type of given StoredProcedure's Parameter in SQL?

Hello, I'm creating 'generic' wrapper above SQL procedures, and I can resolve all required parameters' names and sqltypes, but is there any way how to get it's 'underlying' .NET type? My goal is to do something like: SqlParameter param; object value; object correctParam = param.GetNETType().GetMethod("Parse", new Type[] { typeof(...

what is the SQL to display a number (200909) as Sep 2009 in Teradata 12

what is the SQL to display a number (200909) as Sep 2009 in Teradata 12 ...

How tempDB works?

I am trying to understand the tempDB and following are the doubts popping in my mind. What is the lifetime of data in tempDB? Say a query is doing some Order By and uses tempDB for performing that. After this query finishes, someone else also executes a query which utilizes the tempDB. Will the second query find records written by firs...

prevent duplicate invoice no. against particular ID

I have confusion on how to prevent duplicate InvoiceNo against CompanyId. I just have prepare an Invoice project that has field like CompanyId and InvNo. Both do not have Unique Keys because Company ID and InvoiceNo both have to repeated. as per below CompanyID InvNo 1 1 2 1 1 2 3 1 4 ...

Add a column to a DB2/400 table with a specific ordinal position

Is there an SQL command on the AS400/iSeries/System-i/whatever to add a column to a table in a specific ordinal position, or moving an existing column to a different position? ...

sql between for DAYSOFWEEK

I have a generalized search where I'm looking up average prices for the various days of the week. The problem is I'm not sure how to ask for an odd range. 1-7 works fine, (monday-sunday), but if the user passes a sunday to a tuesday... ie 7-2 it doesn't work. 1-7 (1,2,3,4,5,6,7) 7-2 (7,1,2) etc. How else can I pass a range that is m...

PostgreSQL SELECT the last order per customer per date range

In PostgreSQL: I have a Table that has 3 columns: CustomerNum, OrderNum, OrderDate. There may(or may not) be many orders for each customer per date range. What I am needing is the last OrderNum for each Customer that lies in the date range that is supplied. What I have been doing is getting a ResultSet of the customers and querying ...

How to eliminate duplicate calculation in SQL ?

I have a SQL that can be simplified to: SELECT * FROM table WHERE LOCATE( column, :keyword ) > 0 ORDER BY LOCATE( column, :keyword ) You can see there is a duplicate of "LOCATE( column, :keyword )". Is there a way to calculate it only once ? ...

MySQL question: Indexes on columns!

Hi guys... I've a MySQL question I've two tables (posts and authors) in a one to many relationship (since each post is written by an author and an author can write multiple posts). So here are the tables: Authors: id:BIGINT, name:VARCHAR(255) Posts: id:BIGINT, author_id:BIGINT, body:TEXT I've got 700,000 posts and 60,000 au...

Selecting transactions as a single row

Hey all, I have a requirement where I need to generate a report about current software projects. Two of the columns are the date of the latest milestone and the date of the milestone previous to that. Obviously, milestones are stored in a transaction table so we can have many milestone per project. I've gotten to here so far, but now...

A question about JOIN.

I need to do something like this to fill a parts table: SELECT (CASE t1.part IS NULL THEN t2.part ELSE t1.part END) AS partno, t3.desc FROM t1 LEFT JOIN join t2 ON [certain condition] LEFT JOIN t3 ON t1.part = t3.part OR t2.part = t3.part ...so this will select the value for partno from t2 in case that part i...

OnTaskFailed event handler in SSIS

If I use OnError event handler in my SSIS package, there are variables System::ErrorCode and System::ErrorDescription from which I can get the error information if any things fails while execution. But I cant the find the same for OnTaskFailed event handler, i.e. How to get the ErrorCode and ErrorDescription from the OnTaskFailed event ...

Can't create Informix stored procedure using ISQL command?

I'm having trouble creating this stored procedure on IBM Informix Dynamic Server Version 10.00.FC9 (see Jonathan Leffler's answer to this post here) using the 'isql' command from Informix SQL. I get an error on the ( char for each of his two examples near RETURNING CHAR(8) ex. 1: CREATE PROCEDURE ampm_time(tm SMALLINT) RETURNING CHAR(...

Local vs Global temp tables - When to use what?

I have a report which on execution connects to the database with my_report_user username. There can be many end-users of the report. And in each execution a new connection to the database will be made with my_report_user (there is no connection pooling) I have a result set which I think can just be created once (may be on the first run ...

Oracle external tables. Optimising select queries.

I have to perform many selects from an Oracle external table. I have 10 cursors that look a lot like this (ext_temp is the external table) CURSOR F_CURSOR (day IN varchar,code Number,orig Number) IS select NVL(sum(table_4.f),0) from ext_temp table_4 where --couple of conditions here, irrelevant for the question ...

Handling missing columns in MySQL

Working on parsing a bunch of databases put together in an older, more freewheeling time into a new schema. Basically it's one database per year, with database names like foo98, foo99, foo2000, etc. So for the most recent foo data, I can do something like SELECT foo_person.mdname AS middle_name, ... FROM foo_person, foo_place, foo_thin...

Insert into select and update in single query

I have 4 tables: tempTBL, linksTBL and categoryTBL, extra on my tempTBL I have: ID, name, url, cat, isinserted columns on my linksTBL I have: ID, name, alias columns on my categoryTBL I have: cl_id, link_id,cat_id on my extraTBL I have: id, link_id, value How do I do a single query to select from tempTBL all items where isinsrted = 0 ...