sql

SQL CE: Limiting rows returned in the query

In SQL Compact Edition 3.5 , note that it is the Compact Edition I am talking about- Is there a way to limit the amount of rows to only 2? Something like using LIMIT or TOP. I really don't want to use anything with a SqlCEDataReader, or SqlCEResultSet. I want to do all the limiting in the query. Is this possible now? I have looked around...

ANSI Sql query to force return 0 records

Hi, I'm looking for an ANSI-SQL method to do a Select query without returning any record, but fill a TDataSet's Fields structure. The method I found is by adding a "where 1=0" in any query, for example: Select Id, name, province from customers where 1=0 This is a fairly trivial example, it turns a little more complicated when I have ...

Sql server Integration Services 2008-2005 compatibility

I recently developed an SSIS package on my dev machine using the 2008 version. Later I foud the customer had Sql server 2005 and doesn't plan to upgrade anytime soon. Is there a way to turn the 2008 package into a SSIS 2005 package, like a downgrade wizard? ...

Find position of delimited character in a String (SQL Server)

Hi All, I have a string Variable test=HARIA|123|MALE|STUDENT|HOUSEWIFE i am using | as delimited character. if i want to extract data from 2nd occurence of pipe till 3rd occurrence. i need to get 'MALE' from above string. any help appreciated ...

Change all primary keys in access table to new numbers

I have an access table with an automatic primary key, a date, and other data. The first record starts at 36, due to deleted records. I want to change all the primary keys so they begin at 1 and increment, ordered by the date. Whats the best way to do this? I want to change the table from this: | TestID | Date | Data | | 36 |...

Reading custom data from SQL tables

We have an application that allows the user to add custom columns to our tables (maybe not the best idea, but that's how it is). We are now (re)designing our dataaccess layer (we didn't really have one before) and now we're going to use parameterized queries in our datamappers when querying the SQL-database (earlier we concatenated the...

SQL Server 2008: TOP 10 and distinct together

As the title says, I'm using SQL Server 2008. Apologies if this question is very basic. I've only been using SQL for a few days. Right now I have the following query: SELECT TOP 10 p.id, pl.nm, pl.val, pl.txt_val from dm.labs pl join mas_data.patients p on pl.id = p.id where pl.nm like '%LDL%' and val is not null What I wan...

How do I select the last child row of a parent/child relationship using SQL

Using SQL (MySQL) only I would like to select each of the last child rows of a parent child relationship where the child rows are ordered by a timestamp. For example using the tables invoices and invoice_items, I want the newest (ie: most recently timestamped) invoice_items records for each invoice respectively. -------------------...

SQL Server 2000 Delete Top (1000)

I have a large SQL Server database with a table at about 45 million records. I am archiving this table, and need to remove all entries greater than two years ago. I have the inserting into my archive table working fine, but I'm having issues with efficiency when deleting. My problem lies within the indexes currently on the table. I wou...

Speed up MySQL query containing 300k+ records

I need to lookup all my products (sku's) their latest stock quantity. I have one table (called "stock") with 315k+ records containing this information (a new batch of data is added every day, for most sku's). The reference data is in another table (called "stockfile"). This is the query to do it: SELECT s1 . * , f1 . * FROM stock s1 JO...

Handling Complex WHERE clauses with a PHP Query Builder

There are several ActiveRecord styled query builder libraries out there. Some are stand alone and some come built into frameworks. However, they really have trouble with WHERE and HAVING clauses when it comes to complex SQL. Setting other databases aside - I am trying to come up with a MySQL and PostgreSQL compatible WHERE() method that ...

Very Complex (Postgre/My)SQL examples?

I often find myself in need of very complex SQL examples when testing abstraction concepts or just comparing database styles and structures while working with PostgreSQL, MySQL, and even SQLite. I assume that means there are others in need of insane queries to open our eyes to what is possible and insure our DB layers can handle anythin...

How many rows in a database are TOO MANY?

I've a MySQL InnoDB table with 1,000,000 records. Is this too much? Or databases can handle this and more? I ask because I noticed that some queries (for example, getting the last row from a table) are slower (seconds) in the table with 1 millon rows than in one with 100. ...

Passing variable from shell script to sql statement

I was trying to make cat1.txt as a variable ($2) so that it will be inserted in sql select statement. Is there a way to do this? my cat1.txt 1111 2334 2234 3333 4444 .... .... etc. my SQL Statement set echo off linesize 280 pagesize 0 newpage 0 feedback 1 verify off head off trimspool on alter session set sort_area_size=10485760...

Is latency or my VPN choking my Excel to SQL Server uploads?

I am uploading data from Excel to SQL Server using the following structure: Private Sub ado_upload() Dim objConnection As New ADODB.Connection Dim objCommand As New ADODB.Command Dim strSQL As String Dim strDSN As String Dim intCounter As Integer strDSN = "provider=SQLOLEDB;" _ & "server=<server>;" _ & ...

How to implement Publishing subscriber Replication topology in SQL?

How to implement Publishing subscriber Replication topology in SQL? ...

replace multiple values+in SQL query?

I want to do searching for data using users' entry in a field. That is if user enters "D+t+y+g,k,j,h" want to search for values having letters "d and t and y and g or k or j or h". I tried the PHP str_replace function, but didn't like the result. //kw is text field... if($kw != "") { //here we check for some data in field; if yes, c...

Table structure: some "columns" to be saved as a single text-type field with json structure, alternative: separate table but concerned with performance

Here the deal: I've got a table Billing, which is basically a receipt (for different types of transaction). The app has a feature that you can create new charges (well, all charges except for tax and other constants). Since there would be a dynamic number of charges, we decided to store the charges for a billing on a single text field wi...

SQL Select top frequent records

Hi, I have the following table: Table +----+------+-------+ | ID | Name | Group | +----+------+-------+ | 0 | a | 1 | | 1 | a | 1 | | 2 | a | 2 | | 3 | a | 1 | | 4 | b | 1 | | 5 | b | 2 | | 6 | b | 1 | | 7 | c | 2 | | 8 | c | 2 | | 9 | c | 1 | +----+-----...

Rewriting mysql subqueries with LEFT JOIN

Hello I have a table with such structure: uid sid all integers. This table simulates friendship between two user. All I want to do is to find such records that exist only in one direction. For example: I want to find number of records that have t1.u_id = 15, when there is no records that have t2.s_id = 15 and t2.u_id = t1.s_id. ...