sql

Design SQL Query for following case

Consider tables Table1 id, name 1 xyz 2 abc 3 pqr Table2 id title 1 Mg1 2 Mg2 3 SG1 Table3 Tb1_id tb2_id count 1 1 3 1 2 3 1 3 4 2 2 1 3 2 2 3 3 2 I want to do query to give result like id title 1 MG1 2 MG2 3 Two or More Ti...

SQL Server 2005, Replicating between timezones.

How does SQL Server handle the transfer of the datetime columns when replicating between timezones? ...

What does the slash mean in an SQL query?

What does the slash character mean in this query? This is being used with a MySql database. SELECT Channel, COUNT(Channel) AS Total, COUNT(Channel) / (SELECT COUNT(*) FROM UserClicks WHERE (Date > '2009-12-1' AND Date < '2010-1-1') AND RoleType='member' ) AS Percent FROM UserClicks WHERE (Date > '2009-12-1' AND Date < '2010-1-1') AND Ro...

A select query selecting a select statement

I don't even know if I am doing this query the right way. There is a Sandwiches table that has some 7 fields and 2 of them are comboboxes (Type and Bread). So I made a query that combines all of the comboboxes values into one query, like this: SELECT TypesAndBreads.TBName, TypesAndBreads.Type FROM (SELECT [Sandwiches Types].[Sandwich T...

Are square brackets valid in an SQL query?

I am looking at a note that someone wrote to me and it looks something like this: SELECT Something FROM Foobar WHERE blah='blah' --- [pulls this too - SELECT Something FROM Foobar WHERE something='elsehappens'] I'm trying to figure out if the --- [ comment - QUERY] is just a comment or if it actually means something I haven't seen be...

sql query - join that return only last row

I got a join select statement and i only need the last modified field in the second table. here's the select statement that i have now: SELECT NOM,PRENOM,OEDP.NUM_EMP,N_A_S,SIT_STATUT,PERMIS,DATE_EMBAUCHE,ADRESSE1,VILLE1,PROVINCE1,CODE_POSTAL1,TEL_RESIDENCE FROM ODS_EMPLOYE_DOSSIER_PERSONNEL AS OEDP JOIN ODS_SITUATION_POSTE AS OS...

The SelectCommand property has not been initialized before calling 'Fill'

The SelectCommand property has not been initialized before calling 'Fill' I am getting this error when running StoredProcedure.ExecuteDataSet(); Error happens in DbDataProvider.cs at line 163 ...

How to update two tables in one statement in SQL Server 2005?

I want to update two tables in one go. How do i do that in SQL Server 2005? UPDATE Table1, Table2 SET Table1.LastName = 'DR. XXXXXX' ,Table2.WAprrs = 'start,stop' FROM Table1 T1, Table2 T2 WHERE T1.id = T2.id and T1.id = '010008' ...

sql timezone calculation

I have a table which stores the storecodes and their timezone. Now based on a given local date, I need to know if that date converted to stores local date was a in a weekend or not. Now I already know how to get the weekend part. I am struggling with the conversion. I am actually confused. My table has for example the following two value...

named_scope to order posts by last comment date

Posts has_many Comments I'm using searchlogic which will order by named scopes. So, I'd like a named scope that orders by each post's most recent comment. named_scope :ascend_by_comment, :order => ...comments.created_at??... I'm not sure how to do a :joins and get only the most recent comment and sort by its created_at field, all in...

SQL mapping between multiple tables

This is a SQL design question. First, the setup. I have three tables: A, which is automatically populated based on a query against a linked server. The data in this table cannot be changed; B, which has just a dozen or so rows, containing the names for collections of A's; AtoB, which is the mapping table by which A's are organized into...

SQLite query to join on a range of dates?

I am working with SQLite. Suppose I have a table sales with two columns, date and count, to keep track of how many glasses of lemonade I sold on that date. If I don't sell any lemonade on a given day, I am too depressed to create a new row in the sales table. I'd like to find out the average number of glasses sold over a given date ran...

MYSQL - Retrieve Timestamps between dates

All, I have a MYSQL table with a column called timestamp. It is of DATETIME datatype and has values like "10/1/2009 3:25:08 PM', "10/1/2009 3:30:05 PM', "10/4/2009 3:40:01 PM', etc.. I want to write a SQL query to select all the values in the timestamp field occuring between two dates.. something like this: select timestamp from table...

SQL Server mode SQL

I have a table that list students' grades per class. I want a result set that looks like: BIO...B CHEM...C Where the "B" and "C" are the modes for the class. I can get a mode of all of the grades, but not sure how to get the mode per class ...

Find first non-null values for multiple columns

I'm attempting to get the first non-null value in a set of many columns. I'm aware that I could accomplish this using a sub-query per column. In the name of performance, which really does count in this scenario, I'd like to do this in a single pass. Take the following example data: col1 col2 col3 sortCol ==================...

Disable trigger hangs?

I need to do this from an ASP.NET web app: Alter Table Contacts Disable Trigger All -- Do some stuff Alter Table Contacts Enable Trigger All In some situations the Disable Trigger statement hangs. Where should I start looking to figure out what's causing this? If I restart SQL server it goes back to behaving normally. ...

Export MS Access Database to SQL Server 2008 Express

Is there an easy way to export a MS Access Database backend (Tables & relations) into an SQL Server database, so that it then can be used as a backend for a tailored application written in C# using Entity Framework? The Access Database contains at least 50 tables and the export should not ruin its structure and relations. ...

SQL recursive CTE query, odd results set SQL Server 2005

I am trying to write a recursive CTE query in SQL Server 2005 but am getting an odd set of results. My table is: PairID ChildID ParentID 900 1 2 901 2 3 902 3 4 This is my CTE Query: WITH TESTER (PairID, ChildID, ParentID, Level...

SQL query to conditionally sum based on moving date window

I'm trying to figure out some sliding window stats on my users. I have a table with a user, and columns such as created_at and verified_at. For each month, I'd like to find out how many users registered (a simple group by date_trunc of the created_at), and then of those people, how many verified within my sliding window (call it 60 day...

Would you send this simple SQL back for rework?

We have a web application in which the users perform ad-hoc queries based on parameters that have been entered. I might also mention that response time is of high importance to the users. The web page dynamically construct a SQL to execute based on the parameters entered. For example, if the user enters "1" for "Business Unit" we constr...