sql

mysql aggregate multiple columns by hour.

Hi all, Had a quick look through and couldn't find my question again. So I'm hoping someone here can help. I have a large table with a similar structure to the below. DateTime | InboundUserID | OutboundUserID | CustomerUserID | Cost | Mins | Account Number I'm trying to group the above data into hourly chunks and store the result in a...

Storing Data as XML BLOB

Hi, At the moment the team i am working with is looking into the possibility of storing data which is entered by users from a series of input wizard screens as an XML blob in the database. the main reason for this being that i would like to write the input wizard as a component which can be brought into a number of systems without havin...

Tsql: can i use a variable as database reference

Hi, i want to accomplish this: update @sourceDatabase.dbo.PredictedPrices and then set @sourceDatabase as a variable. But i'm not allowed? Incorrect syntax near '.'. Is there another way? ...

Guidelines for building Data Acces Layer with SQL

There are a lot of information on building DAL with ORM ((N)Hibernate, LINQ to SQL). But I can't find any recomendations on doing it with plain SQL or mixed (ORM + SQL) approach. I wonder, are there any resources (sites, books) on this subject? Besides common best practices I've got a few points of interest: how organize storing ...

executemany problem, MySQLdb

I'm using MySQLdb and run into the following problem: STMT="""INSERT INTO test_table VALUES (%s, %s, %s, %s, %s)""" rows=[('Wed Apr 14 14:00:00 2010', 23L, -2.3, 4.41, 0.83923)] conn.cursor().executemay(STMT, rows) results in: Traceback (most recent call last): File "run.py", line 122, in <module> File "C:\Python25\lib\site-pack...

Multiple conditional counts on one field in SQL

I have two tables where one contains author deatils and the other article details. One author may have many articles. In the article table is a field entitled "Decision" The decision field can be "Accepted" or "Rejected". I want a query to output a table of author name and ID followed by a count of their number of submissions, accepts a...

If statement within switch

I know I'm just thinking of the logic all wrong here but how do I achieve the following: update @table set column1 = case when column1 <> '' then rtrim(column1) + ', ' + rtrim(column2)--if statement here else rtrim(column2) end ...

Assign work in backgroundworker_DoWork() according to condition

In a Winform application,I want to use a single backgroundworker (or may be one for each form) to do different tasks on different events. For eg: Search, Loading Data in grid, opening new forms, sending emails, File transfer etc. How can i manage all this in backgroundWorker_DoWork() and backgroundWorker_RunWorkerCompleted() events? ...

SQL 2000/2005/2008 - Find Unique Constraint Name for a column

Hi, I have a table with a column that needs the data type upgrading. However running any alter script causes errors due to a unnamed unique constraint. I need to drop this constraint but unfortunately I do not know the name. I have a script which currently lists all the unique constraints on the table but I need to find out how to go...

Populating query results with empty rows

I have the following query which I use to return the highest scores in a game but I would like it to be populated by empty rows if there is less than 10 records: SELECT id, MAX(score) mscore FROM scores WHERE id IN (".implode(',', $data).") GROUP BY id ORDER BY mscore DESC" The logic is that an array of user IDs will be passed to the ...

Linq to SQL using group By, and order by count

Hello, This is mysql query: SELECT count(PVersion), PVersion FROM [Products].[dbo].[Active_Details] group by PVersion order by count(PVersion); What will be its LINQ to SQL. ...

Consecutive streak of dates

Hi, Hopefully this isn't a dupe of another question, but I couldn't see it anywhere else - also this is a simplified version of another question I asked, hopefully to get me started on working out how to approach it. I am looking to work out consecutive ranges of payments where there has been at least one payment in each month. I have ...

RIGHT function, not returning whats expected?

Query: SELECT StartDate, EndDate, RIGHT(Sector, 1 ) FROM Table1 ORDER BY Right(Sector, 1), StartDate By looking at this, the query should order everything by sector, followed by the start date. This query has worked for quiet awhile until yesterday where it did not order it properly, for some reason, Sector 2 came before Sector 1. Th...

XOR Constraint in Mysql

Hi. I want to implement a kind of xor constraint on foreign keys in mysql 5.1 There is this table, let's say Entity which can refer to two different kinds of valuesets represented by Tables ValsA and ValsB. Now I would like to implement a constraint wich makes sure that exactly one of those two is mapped, and the other one isn't. In ...

java and jboss, with SQL server. Mulitple insert statements in a native query using entitymanager, not working; but does work in sql

String myQuery1 = "insert into mytable(mycol) values(myval) \ngo"; String myQuery2 = "insert into mytable(mycol) values(myval2) \ngo"; String myQuery = myQuery1 + myQuery2; Query query = myEntityManager.createNativeQuery(myQuery); List<?> insertResultList = queryInsertDefaults.getResultList(); using the eclpise debugger I can see th...

Why is this query failing?

When I run this query: SELECT m.tag_id, m.product_id, count(m.product_id) as dups FROM product_tag_map m INNER JOIN category_tag_map s ON s.tag_id = m.tag_id INNER JOIN cart_product p ON m.product_id = p.product_id WHERE m.product_id = p.product_id AND s.category_id =508 AND s.include =1 AND dups = (SELECT count(s.category_id) as cats F...

SQL - selecting first matching record for join

Using MySQL, I've got a set of tables with 1->N relationships from member -> items -> photos. I'm trying to select a list of a member's items + some columns from the first associated photo (by first I mean the photo with the lowest sort order). Currently I have this query which works, but seems overly complex. Is there an easier way a...

Why does new T-SQL of SQL Server 2008 work on database in compatability mode 80 ?

Experimenting with new features of T-SQL, I've run into a puzzle. Here is some new syntax supported by SQL 2008 and I'd expect it to work on databases set for compatibility mode 100 (i.e. 2008) and not work for compat mode 80 (i.e. 2000). Yet this works for a database set for SQL SERVER 2000 compatibility mode on a SQL 2008 instance of S...

Update Statement in SQLCommand does not work

Hi All, if have the following SQLCommand which should do an Update. The issue is, that I get no errors but it still do not update the database ? SqlConnection sqlconn2 = new SqlConnection(this.connectionString); sqlconn2.Open(); string strCmd = "UPDATE dbo.mydata SET WEB_OBEZ1 = @OBEZ1, WEB_OBEZ2 = @OBEZ2, WEB_...

How can I get Client Side Recordset from Server side Recordset?

I just made a sql query through a component which returned me a server side recordset. Is there a way I can make it as a client side recordset? Creation of the recordset is not in my control. I am not going to need server side recordset again. Basically I want to minimize round trips to the server at the cost of client memory. What cou...