sql

MySQL select help

Hi I have a table that looks like this id : productid : featureid (1, 1, 16) (2, 1, 21) (3, 1, 25) (4, 2, 16) (5, 2, 21) (6, 2, 27) where featureid is a foreign key to another table. I need to select products that have both featureids of 16 and 25, in the example this would be productid 1 but not productid 2. Can someone...

constructing paramater query SQL - LIKE % in .cs and in grid view

Hello friends, I am trying to implement admin login and operators(india,australia,america) login, now operator id starts with 'IND123' 'AUS123' and 'AM123' when operator india logs in he can see the details of only members have id 'IND%', the same applies for an australian and american users and when admin logs in he can see details o...

Problem with user logins after db Restore

I have two SQL 2005 instances that reside on different networks. I need to backup a database from instance A and restore it to a database in instance B on a weekly basis so that both databases hold the same data. After the restore, logins SIDS on database B are changed and therefore users can't log into database B and connection strings...

is of a type that is invalid for use as a key column in an index.

I have an error at Column 'key' in table 'misc_info' is of a type that is invalid for use as a key column in an index. where key is a nvarchar(max). A quick google found this. It however doesnt explain what a solution is. How do i create something like Dictionary where the key and value are both strings and obviously the key must be ...

execute procedure for a sequence of elements (execute theProc (select id from table))

I need to execute the procedure deleteQuestion for each element that was returned by this select query: select id from questions where Stuff = @Stuff execute deleteQuestion id something like: execute deleteQuestion each(select id fom questions where Stuff = @Stuff) anybody knows how ? ...

PHP: How do I find (Oracle) parameters in a SQL query?

Suppose you have a string: "SELECT * FROM TABLE WHERE column1 = :var1 AND column2 = :var2" Now, how do I get an array with all the variables like so: Array ( [0] => :var1 [1] => :var2 ) I've tried it with PHP's preg_match_all, but I struggle with the regex. $varcount = preg_match_all("/ :.+ /", $sql, $out); ...

SQL Query syntax, I want to use INNER JOIN

Hi . I'm working on a windows application project using front end "vb.net" & back end "Ms Access" I have problem in wrinting sql query Actually there are 5 tables Transaction,items,itemtitle,itemtype & userinfo. check the following query & with this referance if u get idea then plz change in correct query Thanking You SELECT TRANSACTI...

circular foreign key. How do i handle them?

Much of my sql code is generated (from POD). Now i have issue where table user_data has a FK to ref_status which points back to two different user_data. My code does the following begins a transaction looks at user_data (and adds it to a list) sees ref_status then repeats #2 with it executes the create table ref_status code Then i g...

SQL indexes for "not equal" searches

The SQL index allows to find quickly a string which matches my query. Now, I have to search in a big table the strings which do not match. Of course, the normal index does not help and I have to do a slow sequential scan: essais=> \d phone_idx Index "public.phone_idx" Column | Type --------+------ phone | text btree, for table "publ...

T-SQL Subquery Question

Hi, i have two queries. For each tuple of query1 i want to run query2. i dont want to use cursors. i tried several approaches using subqueries. query1: select distinct category, Count(category) as CategoryCount from mytable group by category query2: select top 3 Text, Title, Category from ...

Inserting a null value into the database.

Good Morning, Say I have an insert statement: Insert INTO tblTest (fieldOne,FieldTwo,fieldThree) VALUES ('valueOne','valueTwo','null') This statement doesn't seem to want to insert a null value into the database... I have also tried to insert the word "nothing". Has anyone any ideas how to make this work? I am using SQL server 2005...

SQl Server error handling pattern

Hi all. I am not an expert on SQl Server. Is this a valid pattern for handling errors in a batch of SELECT, INSERT...in SQl SERVER ? (I use v.2008) BEGIN TRANSACTION BEGIN TRY -- statement 1 -- statement 2 -- statement 3 COMMIT TRANSACTION END TRY BEGIN CATCH ROLLBACK TRANSACTION END ...

Alternatives to sign() in sqlite for custom order by

I have a string column which contains some numeric fields, but a lot are 0, empty string or null. The rest are numbers having different range, all positive. I tried to create a custom order by. The order would be done by two fields. First I would like to order the fields that have this number >0 and then sort by name. So something this...

SQL to get rows (not groups) that match an aggregate

Given table USER (name, city, age), what's the best way to get the user details of oldest user per city? I have seen the following example SQL used in Oracle which I think it works select name, city, age from USER, (select city as maxCity, max(age) as maxAge from USER group by city) where city=maxCity and age...

How to map combinations of things to a relational database?

I have a table whose records represent certain objects. For the sake of simplicity I am going to assume that the table only has one column, and that is the unique ObjectId. Now I need a way to store combinations of objects from that table. The combinations have to be unique, but can be of arbitrary length. For example, if I have the Obje...

How to save to two tables using one SQLAlchemy model

I have an SQLAlchemy ORM class, linked to MySQL, which works great at saving the data I need down to the underlying table. However, I would like to also save the identical data to a second archive table. Here's some psudocode to try and explain what I mean my_data = Data() #An ORM Class my_data.name = "foo" #This saves just to the 'da...

Table fragmentation in SQL server

Hi Anybody have an idea about Table fragmentation in SQL Server(not Index fragmentation).We have a table ,this is the main table and its not storing any data permently,dat come here and goes out continusly. there is no index on this because only insert and delete staements are running frequently. recently We face a huge delay for the res...

oracle call stored procedure inside select

Hi everybody. I'm working on a query (a SELECT) and I need to insert the result of this one in a table. Before doing the insert I have some checking to do, and if all columns are valid, I will do the insert. The checking is done in a stored procedure. The same procedure is used somewhere else too. So I'm thinking using the same procedu...

Query to get 3rd largest amount and 2nd largest amount from table

How to find 2nd and 3rd largest amount from a table ...

The IMPORTANCE of Indexes on Tables in SQL

I always knew proper indexes were important, but hadn't realized just HOW important until recently. We purchased an off-the-shelf eCommerce solution and implemented it. The SQL server CPU utilization would skyrocket to 99% when we hit about 600 concurrent users. After some investigation, I found that the Users table was NOT indexed prop...