sql

Need SQL help - How can I select rows to perform an insert?

I tried to make the title as clear as possible... here is my scenario: I have 2 tables (let's call them table A and table B) that have a similar schema. I would like write a stored procedure that would select specific columns of data out of table A, and insert this data as a new record in table B. Can someone point me in the write dire...

SQL changing a value to upper or lower case

How do you make a field in a sql select statement all upper or lower case? Example: select firstname from Person How do I make firstname always return upper case and likewise always return lower case? ...

Parameterized Insert statement with transaction throwing an error

I had a parametrized insert statement that was working well and I needed to add a select statement and wrap it all in a transaction in order to get data for one of the fields for the insert. I'm not sure if I've hit a limitation with ASP/ADO or if I've just got something syntactically wrong. Here's my code: set oSQLCommand = Server.Cr...

mysql update statement behaves differently based on whether a user variable exists

I'm reseting a sort column that has duplicate or missing values like so: set @last=''; set @sort=NULL; update conf_profile set sort= if( @last=(@last:=concat(org_id,',',profile_type_id,',',page,',',col)), (@sort:=@sort+1), (@sort:=0) ) order by org_id,profile_type_id,page,col,sort,id; (Go through all th...

Simple SQL code evades me.. Unionize two mismatched tables.

I'm selecting 1 field from 1 table and storing it into a temp table. Sometimes that table ends up with 0 rows. I want to add that field onto another table that has 20+ fields Regular union won't work for me because of the field # mismatch. Outer wont work for me because there is nothing to compare. NVL doesn't work on the first temp t...

Simple T-SQL Join question

I am trying to select a record out of the table1 by joining table2 and using table2 columns in the WHERE statement. Col1 and Col2 in table1 can be stored in col1 of table2. I need to join col1 of table2 with either the value of col1 or col2 in table1 here is the sql statement I created so (pseudo): SELECT t1.Col1, t1.Col2, t...

tool for detecting non-parametrized sql in java jdbc code

I'm looking to inspect SQL statements in Java/jdbc code to ensure that the SQL to be executed is of acceptable quality. Neither PMD not Findbugs appears to have JDBC or sql rules. I could use p6spy to log the SQL and look at that way, but this is manual. I'm wondering if the strategy of of using PMD/Findbugs/etc to create a rule that ...

Is 20 SQL Queries per page load really considered a lot?

I was reading Jeff Atwood's blog on Behold WordPress, Destroyer of CPUs and saw that many people there considered 20 SQL Queries per page load to be a lot. What is the average amount of queries per page nowadays for a highly dynamic page with auto suggest, auto refreshing of data, customized pages, and the kitchen sink? For a simple ...

Sample [English] Dictionary SQL Script to populate table?

Does anyone know of a link to a reference on the web that contains a sample English dictionary word script, that can be used to populate a dictionary table in SQL Server? I can handle a .txt or .csv file, or something similar. Alternatively, I'm adding custom spellchecking functionality to my web apps...but I don't want to integrate th...

SQL "SELECT IN (Value1, Value2...)" with passing variable of values into GridView

Hi there, I have a strange encounter when creating a GridView using "SELECT..WHERE.. IN (value1, val2...)". in the "Configure datasource" tab, if i hard code the values "SELECT ....WHERE field1 in ('AAA', 'BBB', 'CCC'), the system works well. However, if I define a new parameter and pass in a concatenated string of values using a varia...

how remove htmltags from database

how to remove html elements in a text field from sql server ...

Where to look for database samples/schema?

I found http://www.databaseanswers.org/data_models/ very useful. Any other suggestions? ...

What is the correct/ fastest way to update/insert a record in sql (Firebird/MySql)

I need some SQL to update a record in a database if it exists and insert it when it does not, looking around there looks to be several solutions for this, but I don't know what are the correct/ accepted ways to do this. I would ideally like it to work on both Firebird 2 and MySQL 5 as the update will need to be ran against both database...

Book recommendation for advanced SQL design, scripting and optimiziation.

What is a good book to become an SQL master? That is, learn how to tweak queries, table design, optimizing the server, etc. I use mostly MySQL and Postgres, but maybe a DBMS agnostic book would come handy. The "optimizing the server" part is probably specific to each DBMS. I would like to know of a good book to learn advanced SQL and d...

Database Mirroring and Logshipping

I have setup both mirroring and and log shipping on 8 databases of about 10 GB each size on same instance, but now when I want to mirror another database it very long to display the Database Properties page. Any suggestion for this problem. ...

SQL Server Clustered Index - Order of Index Question

I have a table like so: keyA keyB data keyA and keyB together are unique, are the primary key of my table and make up a clustered index. There are 5 possible values of keyB but an unlimited number of possible values of keyA,. keyB generally increments. For example, the following data can be ordered in 2 ways depending on which key c...

self join query

Consider the following table: mysql> select * from phone_numbers; +-------------+------+-----------+ | number | type | person_id | +-------------+------+-----------+ | 17182225465 | home | 1 | | 19172225465 | cell | 1 | | 12129876543 | home | 2 | | 13049876543 | cell | 2 | | 15064223454 | home | ...

How to find unclosed connection? Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

I've had this problem before and found that basically I've got a connection that I'm not closing quickly enough (leaving connections open and waiting for garbage collection isn't really a best practice). Now I'm getting it again but I can't seem to find where I'm leaving my connections open. By the time is see the error the database has...

Get most common value in SQL

I have a table like this: Column | Type | Modifiers ---------+------+----------- country | text | food_id | int | eaten | date | And for each country, I want to get the food that is eaten most often. The best I can think of (I'm using postgres) is: CREATE TEMP TABLE counts AS SELECT country, food_id, count(*) as count...

Diagnosing Programming Errors

We've all hit those errors that take hours/days to debug, only to find it was because of a misplaced assumption, wrong input data, or some other unseemly error. As an example, I just spent 6 hours trying to find an error in a stored procedure. It fired fine in Query Analyzer, but failed in code. The end result was a space that didn't ...