sql

How best to develop the sql to support Search functionality in a web application?

Like many web applications (business) the customer wants a form that will search across each data field. The form could have 15-20 different fields where the user can select/enter/input to be used in sql (stored procedure). These are quite typical requests by the user that most every application has to deal with. The issue really at h...

duplicates in a join

the following SQL is returning every BT.Bt_Name where L.date_back is Null. I only wish to select the BT.Bt_Names where L.Bc_id is duplicated SELECT BT.Bt_Name FROM Book_Title BT INNER JOIN ( Book_Copy BC INNER JOIN Loan L ON BC.Bc_id = L.Bc_id ) ON BT.Bt_id = BC.Bt_id WHERE L.Date_back Is NULL GROUP BY BT.Bt_name HAVING COUNT(L.Bc...

Problem with DATE type in SQL Server

I'm trying to CREATE a TABLE with an attribute of type DATE in Microsoft SQL Server 2008. However, when I execute the query, I get the error: Column, parameter, or variable #3: Cannot find data type DATE. I consulted the documentation, and it indicated that DATE is a valid type in SQL Server. It works if I replace "DATE" with "DATE...

Is there a better, more "Standard" way to perform SQL queries in PHP without using a framework?

For the longest time, I've been using the following basic formatting for SQL queries within my PHP: $sql = "SELECT * FROM `user-data` WHERE `id` = '".$id."' LIMIT 1;"; $fn = mysql_fetch_assoc(mysql_query($sql)); While this works flawlessly, it can get really messy for longer bits of code, and something deep inside of my conscience cri...

mysql order_by question

Query table articles: select * from articles where article_id in(98,97,96,99) returned result ordered like record 96 ... record 97 ... record 98 ... record 99 ... but I prefer the result ordered the same as 'in(98,97,96,99)'. Any tricks to make it possible? Thanks. ...

Cheap/free query tool for multi-database Java/hibernate developer

I'm very interesting in inexpensive (better free) SQL query tool for working with multiple databases. Generally speaking it should works with all databases which Hibernate supports, but it must work with Microsoft SQL Server (2000/2005/2008), Oracle (9i/10g/11g), Postgres 8.x, Sybase, Firebird, MySQL and HSQLDB. Must have features: ...

Query to obtain average each 30 seconds

How can i calculate average of each 30 second? The following is the table structure Price TTime every minute 5-60 records inserted. The time is inserted by getDate(). I have to calculate average of every 30 seconds. ...

VS2008 not working with SQL Server 2008 Express ???

Hi, I've both VS2008 and SQL Server 2008 Express installed in my computer. When I try create a new DB or attach an existing one, I get the following error message:"This version of server is not supported - Only versions up to 2005 are supported." From that, I'd like to know: Is it possible that VS2008 with SP1 be not able to support...

SQL Server: How to get all child records given a parent id in a self referencing table

Hi I have a which references itself and I need to be able to select the parent and all it's child records from a given parent Id. My table is as follows: ID | ParentID | Name ----------------------- 1 NULL A 2 1 B-1 3 1 B-2 4 2 C-1 5 2 C-2 So ...

Tool for comparison of SQL Server query plans?

Does anyone know of a tool that can be used to compare (relatively complex) query plans? I'm not looking for a guide to query plans, but just a tool that enables me to quickly see e.g. the different index use. EDIT: just to make it clear, I'm not looking for information about the plan, but a tool that can quickly point out the differenc...

Which control to design an asp.net page with sql?

I still have loads to learn. At the moment I have stored procedures, and a gridview bound to them. It works, but I want to learn new and better ways of doing things. I discovered I should be using ROW_NUMBER() to help keep my queries relevent to what fits in the paged gridview, which I am going to be implementing. But what IS the best,...

SQL, remove appearances of a comma at end of the line.

My data looks as follows MyText ------- some text, some more text, even more text,, some text,,,, some text, some text,,, some text, some more text, even more, yet more, and again I would like to achieve: MyText ------- some text, some more text, even more text some text some text, some text some text, some more text, even more, yet ...

Row convert to column in sql server 2005?

Hi, My table value is Esino ym workeddays name 1 200906 25 a 1 200907 24 a 1 200908 27 a 2 200906 22 b 2 200907 25.... b I nedd out output is Esino ym1 ym2 ym3 w1 w2 w3 name 1 ...

How can I print the SQL query executed after Perl's DBI fills in the placeholders?

I'm using Perl's DBI module. I prepare a statement using placeholders, then execute the query. Is it possible to print out the final query that was executed without manually escaping the parameters and dropping them into the placeholders? Thanks ...

can we pass parameter to a view in sql?

Can we pass a parameter to a view in Microsoft SQL Server? I tried to create view in the following way, but it doesn't work: create or replace view v_emp(eno number) as select * from emp where emp_id=&eno; ...

Replacing sequence with random number

I would like to replace some of the sequences I use for id's in my postgresql db with my own custom made id generator. The generator would produce a random number with a checkdigit at the end. So this: SELECT nextval('customers') would be replaced by something like this: SELECT get_new_rand_id('customer') The function would then re...

How do you generate random unique identifiers in a multi process and multi thread environment?

Every solution I come up with is not thread save. def uuid(cls,db): u = hexlify(os.urandom(8)).decode('ascii') db.execute('SELECT sid FROM sessions WHERE sid=?',(u,)) if db.fetch(): u=cls.uuid(db) else: db.execute('INSERT INTO sessions (sid) VALUES (?)',(u,)) return u ...

RBAR vs. Set based programming for SQL

Having read this link on RBAR and this, my understanding of RBAR amounts to this: Anything that have loops and cursors Anything that's not set based I know this sounds kinda wholly which is why I am asking if anyone has a more elegant explanation as to what set-based programming is (within SQL context). ...

How to get data from remote database using TSQL?

Is it possible to get data from remote server using JUST TSQL? I mean to do it just with script and without any actions (setting up linked servers and etc) on local server. Need to query something Like this: SELECT * FROM dbo.Users WHERE UserID NOT IN (SELECT UserID FROM [192.168.1.100].dbo.Users) ...

Reading a text file and exporting its contents to sql

I'm trying to have files(.shp and image file types) that are listed(the location) in a text file exported to a database, by importing it into the manifold program and then exporting them from there into sql. The code is in C# and any references, similar coding and examples are welcomed. info: I'm using Manifold System 8.0 Ultimate Editi...