sql

MySQL WHERE always needs a table

I'm getting a syntax error on the following query: SELECT 1,2 WHERE 1=1 But this query works fine: SELECT 1,2 FROM (SELECT 1) t WHERE 1=1; It almost looks like a WHERE clause always needs a table. Sometimes, in the depth of a complex query it's nice to use a SELECT/WHERE combo to turn on and off certain features. Is there a way...

How to search content of a routine/(SP-Trigger-function)

I need to search text within a routine body (Stored Procedure, function, trigger) of all routines within a database.. How do I do that.. Thanks ...

Unable to Select Record from Database

I am learning PHP and SQL, and I'm trying to figure out how to select a record from a database. I created a function called selectById() Right now in the browser displayed is "Error:" but, no specific error was displayed. // function selectById -------------------------------------------------------------------- function selectBy...

MySQL: How To Check If User (Self) Has Permission To Create Temporary Tables

What query would I have to use to check if the querying user has permissions to create temporary tables in the database? ...

how to support many sql queries on a web at the same time?

The question is: if I have a webpage hosted somewhere. The backend environment is LAMP supported. For example: whenever a user opens a new page, it will create a new mysql connection to the MySQL database server and do a corresponding query. We all know that MySQL has a max_connection limit (100 for version <5.1 as default). Of course...

rewriting query in PostgreSQL

After a db schema change, what was a column is now computed in stored procedure. Is it possible to make this change seamless for application programs? So that when a program sends a query like SELECT id, value FROM table ...it instead gets a result of SELECT id, compute_value() AS value FROM table I thought...

Error converting data type varchar to bigint. Inline sql statements

Hello, This is the code i have used to get LocationID from database with MerchantID. I am getting an exception from Fill dataset part. Please help me out,. The error is Error converting data type varchar to bigint. public DataSet getLocationID(long MerchantID) { //long LOCID = null; try { SqlParameter[] parameters =...

Optimise Microsoft Access Nested Queries

I'm trying to run a set of nested or stacked queries in Microsoft Access. As in I run Query 1 -->I use the results of Query 1 in Query 2 ---->I use the results of Query 2 in Query 3 ------>I use the results of Query 3 in Query 4 Query 3 takes less than 1 second to run. -- Query 3 results -- PARTID INFO 266 156-10 266 165-10 266 183...

mysql select timestamp as date string

Hi! I have a table with the column "create_time" which is of type 'INTEGER' and represents the time since epoch. I'd like to select all rows & columns while displaying this row as a date/time in UTC format. How do I do that? ...

Php mysql, variable help query help

I have this mysql query: UPDATE `table`.`wp_12_postmeta` SET `meta_value` = 'yyy' WHERE `wp_12_postmeta`.`meta_id` =5 LIMIT 1 ; How do i incorporate this: instead of wp_12_ i want a variable $prefix (variable holds wp_4_, wp_3_, etc) instead of yyy i want a value $perf (variable is a name ) instead of 5 i want a value $meta...

create columns from transaction type in table

I have an SQL query that groups by transaction type and then sums amount, but would like the summed amount to be in a column for each transaction type i have this: select Job, sum(amount) as Amount, transaction_type from JCT_CURRENT__TRANSACTION WHERE transaction_date >= {?Start Date} and transaction_date <= {?End ...

MySQL get row position in ORDER BY

With the following MySQL table: +-----------------------------+ + id INT UNSIGNED + + name VARCHAR(100) + +-----------------------------+ How can I select a single row AND it's position amongst the other rows in the table, when sorted by name ASC. So if the table data looks like this, when sorted by name: +-----...

SQL queries exceedingly slow when referencing primary key

I have a MS SQL table with about 8 million records. There is a primary key (with clustered index with only 0.8% fragmentation) on the column "ID". When I run seemingly any query referencing the ID column, the query takes very long (and in fact ultimately crashes my application). This includes simple queries like "SELECT * FROM table WH...

Flexible Persistence Layer

I am designing an ASP.NET MVC 2 application. Currently I am leveraging Entity Framework 4 with switchable SQLServer and MySQL datastores. A requirement recently surfaced for the application to allow user-defined models/entities to be manipulated. Now I'm unsure if a SQL/relational database is appropriate at all; instead of adding/removi...

How do i get top n records of each category

Hi guys, I am here to get records based on categories. My table foo has fields [id, name, class]. my records can be like: 1, ram, 10 2, hari, 9 3, sita, 10 4, gita, 9 5, rita, 5 6, tina, 7 8, nita, 8 9, bita, 5 10,seta, 7 ...and more... Now i would like to get result with each record from different class.. i.e something like 1, r...

SQL 2000: Variables in update statements and order of evaluation

I have an update statement in this form: declare @v as int update tbl set @v=tbl.a=(select sum(amount) from anothertable at where at.x = tbl.y), tbl.b = @v/2 The reason I would like to use a variable is to avoid using the subquery twice. The problem is that I have not found any references stating that this is safe. Is the second a...

problem with creating stored procedure and view in sql server

I have following stored procedure code when i execute it gives an error saying invalid column name Lat , Lng .These Lat and Lng variables are parameters called from c# code behind with sql query indicated at last in this particular paragraph. CREATE FUNCTION spherical_distance(@a float, @b float, @c float) RETURNS float AS BEGIN RET...

Convert rows to columns allowing duplicates

Consider the following table and rows: Listing A. ID, name, event, type 1, 'John Doe', '2010-09-01 15:00:00.000', 'input' 1, 'John Doe', '2010-09-03 11:00:00.000', 'input' 1, 'John Doe', '2010-09-04 17:00:00.000', 'input' 1, 'John Doe', '2010-09-02 15:00:00.000', 'output' 1, 'John Doe', '2010-09-03 16:00:00.000', 'output' 1, 'John Doe'...

Best way to "Save As" or "Rename" a database in VB.NET using SQL

In my application I wanted to Open an existing blank database (called "New File" - with full structure but no data), then fill the database using the application then save the database with a different name and path. What is the most appropriate method of doing this? I use SQLEXPRESS and VB.NET 2010. ...

SELECT *, COUNT(*) in SQLite

Hello. If i perform a standard query in SQLite: SELECT * FROM my_table I get all records in my table as expected. If i perform following query: SELECT *, 1 FROM my_table I get all records as expected with rightmost column holding '1' in all records. But if i perform the query: SELECT *, COUNT(*) FROM my_table I get only ONE row...