sql

c# datetime to sql with including seconds

hi, i am trying to save (using linq) the date and time to an SQL field (datetime data type) using Datetime.Now but the seconds are not coming through. Does anyone know how to rig that up? Ta. ...

Problem in mysql when ordering by more than one column using ORDER BY FIELD

I have a MySQL query where I sort by field like this: "... WHERE (patterns.id IN($idsJoin)) $where ORDER BY FIELD($idsJoin2) LIMIT 0 , $numLines"; where $idsJoin2 is something like this: my $idsJoin = join(',',@ids); my $idsJoin2="patterns.id, ".$idsJoin; and "@ids it's an array with numbers I want to order...

MySQL: printing data just once for each grouping

I'm coding in PHP/MySQL and have the following query to fetch products and product group data: SELECT products.id,products.name,product_groups.id,product_groups.name FROM products INNER JOIN product_groups ON products.id=product_groups.id WHERE products.name LIKE '%foobar%' ORDER by product_groups.id ASC So this query fetches products...

VBA select not returning any rows

Below query is not returning any rows into the listbox.There is no error message: lstDiff.RowSource = "select TestScenario,TestId from tblTesting where empid= '" & Me.txtEmpId.Value & "' and testid= '" & Me.txtAutoNumber.Value & "'" Could anyone help? ...

how to handle 1 value returned from sql in php

$query = "SELECT val FROM table WHERE id = 1"; mysql_query($query); This returns a single peice of data from the database. all the ways I know how to deal with this data are mysql_fetch_array() and mysql_fetch_assoc() is there a way to deal with 1 peice of data that doesn't involve pulling it into an array? ...

SQL Server table creation date query

How can i get the table creation date of a MS SQL table using a SQL query ? I could not see any table physically but i can query that particular table ...

reverse mysql_real_escape_string

I have a peice of data that is large and will probably contain quotes and double quotes. I'm using mysql_real_escape_string() to store it safely. When I pull it out to look at it, all the quotes are escaped. I tried using str_replace to just get rid of all the quotes, but that turns \r\n's into rn. :( How can I reverse it so the data ...

SQL Server - Guid VS. Long

Hello! Up until now i've been using the C# "Guid = Guid.NewGuid();" method to generate a unique ID that can be stored as the ID field in some of my SQL Server database tables using Linq to SQL. I've been informed that for indexing reasons, using a GUID is a bad idea and that I should use an auto-incrementing Long instead. Will using a lo...

.NET/C# Drizzle database client

I am planning to use Drizzle in my next C# Mono app. Since there is no C# client available for Drizzle, I thought I would have a stab at writing my own by converting the Java client, and then making it work with DBLinq. Having seen the Java client, I realise that it's a longer job that I had anticipated, and I don't have the time. Bes...

How can I update my SQL Server database schema?

Usually throughout development of a project I will deploy frequently, just to make sure I wont have any problems in production. Also, throughout development, I find myself changing the database's schema. How can I easily update the database in production? I have been dropping the old database and reattaching the new one. Is there a fa...

SQL 'Like' operator and 'aa'

We've stumbled upon a very odd problem in one of our applications. The seach engine uses a stored procedure to compare a bunch of filters. However when a specific type of string is inserted, the sql server (2005) behaves very odd. I've isolated the problem to the following: select 'match!' where 'teliaa' like '%telia%' The collation ...

Linear regression confidence intervals in SQL

I'm using some fairly straight-forward SQL code to calculate the coefficients of regression (intercept and slope) of some (x,y) data points, using least-squares. This gives me a nice best-fit line through the data. However we would like to be able to see the 95% and 5% confidence intervals for the line of best-fit (the curves below). ...

What does a transaction around a single statement do?

I understand how a transaction might be useful for co-ordinating a pair of updates. What I don't understand is wrapping single statements in transactions, which is 90% of what I've ever seen. In fact, in real life code it is more common in my experience to find a series of logically related transactions each wrapped in their own transa...

Database vs. Front-End for Output Formatting

I've read that (all things equal) PHP is typically faster than MySQL at arirthmetic and string manipulation operations. This being the case, where does one draw the line between what one asks the database to do versus what is done by the web server(s)? We use stored procedures exclusively as our data-access layer. My unwritten rule ha...

When should I use stored procedures?

When should I be using stored procedures instead of just writing the logic directly in my application? I'd like to reap the benefits of stored procedures, but I'd also like to not have my application logic spread out over the database and the application. Are there any rules of thumb that you can think of in reference to this? ...

Joining Tables from multiple SQL Server databases located on separate severs

What is the recommended way of joining SQL Server database tables located on databases which are on different servers? All databases will be on the same network. ...

SQL: creating a string array and query = like all strings in array

I have SQL Server 2005 Report that takes a parameter in a query string that searches customer names. The problem is some customers like to put in a middle initial so when the user 'John Smith' this does not bring up 'John Q. Smith'. Using only sql, how would I split a string into an array by whitespace then search records matching each ...

only update 1 column with linq

Hi, I'm using linq to retrieve a row from a table in the database. Now I only update 1 column. Then I update it back into the database. this goes well, except for the times any of the other fields is changed by another process/thread/user In that case I get an exception (optimistic concurrency), telling me to look out, values have been...

Incremental count column based on another column contents

I need to populate a column with the running count based on another column contents. The table is like this: count seq_num 1 123-456-789 1 123-456-780 1 123-456-990 2 123-456-789 2 123-456-990 So, as the seq_num column changes, the counter restes to '1' and as the co...

combining two queries

This first query grabs all the transaction_details for a particular date range This is tricky though, I actually need the sum of sums in this query if that makes any sense. SELECT td.transaction_id, sum( IF( coalesce(ti.na, -1) = 0 AND coalesce(ti.special_info_type, -1) = 0 AND coalesce(ti.item_type, '') = 'P' AND...