sql

Php Syntax Help

I'm working on a search function, it was working fine four days ago, now it's returning this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND state = 'AZ '' at line 1 what is the proper syntax for this line? if($search_state !== "") { $qu...

How to insert, if I need to pick up Primary id for other table

SELECT * FROM tableFoo LEFT JOIN tableBar ON tableFoo.commonColumn = tableBar.commonColumn WHERE tableBar.commonColumn IS NULL Above will select records, I would like to insert Code below will insert id to third table. INSERT IGNORE INTO jos_mt_links (link_id,link_name,alias) VALUES(NULL,'tex2','hello'); # generate ID by inser...

Mysql Using JOINs and WHERE statment. What is this difference?

What is the difference bettween SELECT a.AccountId FROM Accounts AS a JOIN domain as d; and SELECT a.AccountId FROM Accounts AS a JOIN domain as d WHERE a.AccountId=d.AccountId; I thought JOIN is an inner join which only matches when the left AccountId is == to the right AccountId. Wouldn't the above be exactly the same? I got diff...

Capturing Stored Procedure Parameters via Table Trigger

I have a table that has a Trigger associated with it for Update, Insert and Delete. The Trigger works fine and executes. Here is the code for my trigger: CREATE trigger [dbo].[trg_audit_TableName] ON [dbo].viewLayers FOR INSERT, UPDATE, DELETE AS SET NOCOUNT ON declare @inputbuffer table (EventType nvarchar(30),Parameters int,EventInf...

SQL Stored Proc Executing Select before gettting values from other procs

Got a strange problem created a little stored proc which need to execute a couple of other stored procs to get some values before executing the main select statement see below, set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[usp_get_ApplicationUserServiceRoles] @UserId int, @ApplicationName varchar(50), ...

mysql: only log a certain db or ignore other db's?

Hi, I'm logging output with log = /var/log/mysql/query.log and this works ok, but I only want to log requests to one database and not the others. How can I do this? Thanks! ...

MSDTC (Distributed Transactions) support in MySQL

Does MySQL support MSDTC? ...

SQL function to sum values/totalize volumes over specific time periods

I am trying to calculate the total volume of water irrigated over a section of land. What I have is the change of flow at an instant of time recorded into a SQL database. -this is measured in cubic meters per hour. Date Time Flow Value 2009/10/22 04:00:00.0 0 2009/10/22 04:00:16.2 23 2009/10/22 04:00:20.6 34 2009/10/22 04:00:...

MySQL Slow Query Analysis and Indexing

Recently, we've noticed a particular query popping up in our slow query logs taking quite some time. I've analyzed it to the best of my ability, but can't figure out for the life of me why it's taking so long, and why the indexes we've set up aren't being used. Here's a simplified (i.e., readable) version of the query for the purpose ...

mysql: export single row, but with all dependencies

Mysql question. I want to export one single row from one table with a catch: I want to pull together with it all the rows in all other tables referenced from the initial row by foreign keys - and referenced from the new rows too, recursively, until I get all rows that the initial one "needs to exist". How can I do that? ...

Linq Join - Duplicates

I have Two tables. 1.Users table (Username , Name) 2.Picture table( ID , Username , IsPrimary) Each user can have zero to many pictures. I'm Trying to write a query that will return all users (with or without pictures) and a single picture Id (of the picture with IsPrimary = true). I wrote this Linq query : var v = from u in Users ...

t-sql Summing differences between timestamps

Hi, I'm tracking machine state which can be 0,1 and 2, and storing that data in sql table with time_stamp. I have table in sql server with next fields: id(int) time_stamp(datetime) machine_state(int) Machine state is connected with machine condition: machine_state =0 -machine stooped machine_state =1-machine with alarm machine_state =2...

MSI script to check sql server 2000 PE for a db name and not rerun db install script

Greetings, I am seeking help on building a script that will allow my msi installer to check for an exsisting db or exsisting user on the local server of sql server 2000 Personal Edition, during the pre install, the script needs to return the sql response and not run/resintall the sql scripts if the db name or db user is on the server al...

Pass table as parameter into sql server UDF

I'd like to pass a table as a parameter into a scaler UDF. I'd also prefer to restrict the parameter to tables with only one column. (optional) Is this possible? EDIT I don't want to pass a table name, I'd like to pass the table of data (as a reference I presume) EDIT I would want my Scaler UDF to basically take a table of values ...

Need help with the Merge statement.

I want to update a table called Sorels_ext from a table called Sorels. The link between them is the fkey_id of Sorels_ext equals the identity_column of the Sorels table. This is my first attempt at a Merge statement and I'm trying to learn the syntax. MERGE Sorels_ext AS SORe USING (select SOR.identity_column, CASE WHEN left(SO...

Add 30 days for date in db

I have publish up date and publish down date in my DB. Currently they are both same dates. How do I change it (during mysql insert) so publish down date is 30 days past publish up date. I am using $pubDate Thanks ...

Selecting with preference in SQL Server

I have a table in SQL Server 2000 with data similar to the following: ReferenceNumber ReferenceValue 00001 Not assigned 00002 Not assigned 00002 ABCDE in which each ReferenceNumber can appear multiple times in the table, either with a ReferenceValue of 'Not assigned' or a true ReferenceValue. ...

Error in my SQLite syntax

New to SQLite so I don't know what I'm doing wrong. I'm just getting an error saying: SQLSTATE[HY000]: General error: 1 near "CREATE": syntax error Here's my SQL: CREATE TABLE users ( id INTEGER NOT NULL PRIMARY KEY, date_created DATETIME NOT NULL, date_updated DATETIME NOT NULL, username VARCHAR(32) NOT NULL, password VARC...

SQL Query for total time water pump on between dates

I have a water pump that the run state is stored in a mssql database every 10 seconds along with the time of day. The pump cycles often through out the day. How do I query for the total time the pump was on during the day? ...

Is it possible to insert multiple rows at a time in an SQLite database?

In MySQL you can insert multiple rows like this: INSERT INTO 'tablename' ('column1', 'column2') VALUES ('data1', 'data2'), ('data1', 'data2'), ('data1', 'data2'), ('data1', 'data2'); However, I am getting an error when I try to do something like this. Is it possible to insert multiple rows at a time in an SQLite databa...