sql

Can I depend on order of output when using row_number()

I believe the answer is no. And am looking for a counter example to show that order of output is not guaranteed, absent an order by clause. consider: create table #order (orderId int primary key clustered , customerId int not null -- references customer(customerId) , orderDateTIme datetime not null) insert into #order values ...

Can I use MySQL to join two tables based on relationships with a third table?

Let's say you have three tables named Item, Event, and Seat, constructed as such: Item Id (int) Event_id (int) Section (int) Event Id (int) Venue_id (int) Configuration (int) Seat Id (int) Venue_id (int) Configuration (int) Section (int) Face_value (int) I'm trying to construct a MySQL query that pulls all entries from the Item table...

YearFrac in Sql 2005

How do I write the YearFrac function that comes with Excel in Sql 2005? ...

SQL Unique Values Numbering Sequence for Pivot

For reporting purcposes, I need to Pivot results of a query that is unique on each record. My current statement is: SELECT * FROM Sales AS x WHERE (select count(*) from Sales where customer_name=x.customer_name and order_date>=x.order_date)<=5 ORDER BY customer_name, order_date, price; A sample of the Query output is: custo...

Get Day of Week in SQL 2005/2008

Say I have a date 01/01/2009, I want to find out what day it was e.g. Monday, Tuesday, etc... Is there a built in function for this in Sql2005/2008? Or do I need to use an auxiliary table? ...

hibernate insert into select

Hi, How can I generate insert statements like insert into table (sequence.nextval, 'b0) using hibernate? Hibernate currently selects the sequence.nextval value and only then it uses the value to insert the entry in the table. Note: I'm not very fond of custom id generators. ...

How do you pad a NVARCHAR field with zeros using T-SQL in a SQL Server 2005 DB?

I have an Orders table that stores the Ordernumber as NVarChar. We manually increment the order number by querying for the biggest order number ordering in descending order and returning the top 1 and then adding 1. We have this implemented in Microsoft CRM 4.0. e.g Order Numbers (NVarchar) 99 456 32 When I query the above values i...

What is the difference between a hash join and a merge join (Oracle RDMBS )?

What are the performance gains/losses between hash joins and merge joins, specifically in Oracle RDBMS? ...

SQL Server - A script to loop through all remote tables and perform "Select * into ...'

Here's what I'd like to do. For each table in linkedserver.database whose tablename is like 'text%' (inside loop) A. If current_table exists locally, drop it B. select * into table.name (local) from linkedserver.tablename (copy schema + data) C. Possibly check for errors and Print some text about it? Next Any idea if this script ...

How to extend the timeout of a SQL query

This is not a connection timeout as a connection to the database is made fine. The problem is that the stored procedure that I'm calling takes longer than, say, 30 seconds and causes a timeout. The code of the function looks something like this: SqlDatabase db = new SqlDatabase(connectionManager.SqlConnection.ConnectionString); return...

Google App Engine: Datastore not a traditional relation database. What is meant by this?

From the GAE getting started guide Because the App Engine datastore is not a traditional relational database, queries are not specified using SQL. Instead, you can prepare queries using a SQL-like query language we call GQL. What do they mean by "not a traditional relational database" and what implications does this have ot...

How much should doctrine record do?

Hello I'm creating my own CMS and use doctrine for database. Now I wonder, when I crate Post record, how much work should that record do? An example: I have Post -> Categories relation (one to many), should I create separate functions to append categories (to look if Post already has category, etc. ) or should Post do that using acc...

SQL Server 2000 dropping indexes

Can anybody know how to remove all the indexes from database ? ...

Finding all Nullable Columns in SQL 2000 Database

How to find out column with NULL values allowed in the insert in whole database ? ...

fill factor of SQL Server 2008

Hello erveyone, I am new to SQL Server 2008 fill factor, as mentioned here in SQL Server 2008 BOL, http://msdn.microsoft.com/en-us/library/ms177459.aspx My 2 confusions, Whether fill factor applies to index page? Or applies to both index and data page? At the beginning, seems fill factor applies only to index page -- "The fill-facto...

select x posts, regardless of number of inner joined category rows

A table with blog posts that are in one or more categories. Now I want to select 10 posts and having the categories for each of the posts. That means inner joining each post on the post-to-category table etc. Problem: limit 10 gives only 10 rows (eg one post with 10 categories). I want to have 10 different posts with all categories for ...

Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Clearly, when GROUP BY clause used, columns that are not aggregate function should be part of the group by clause. The problem here is, I cannot contain HTTPADDRESS & DATEENTERED columns in GROUP BY clause. Also, I dont know a function that will give me the latest entries of all. edit: I use sql-server. I would use LAST function if I w...

SQL Statement will not execute in C#?

Hey Guys, here is my code for this, the only help i get from VS is that the INSERT INTO statement syntax is incorrect? I have gone through all of the code and just cannot see where i have gone wrong, can someone gimme a hand please? public void New(string ApplicationStartupPath, string FileName, string Department, string Month,...

TSQL Left Join with multiple right hand rows

When you perform a left join in TSQL (MSSQL SERVER) is there any guarantee which row will return with your query if there are multiple rows on the right? I'm trying to use this to exploit an ordering on the right table. so Select ColA, ColB, ColC from T Left Outer Join (Select ColA, ColB, ColC from T--CLARIFIED, this is a sel...

Extracting hours from a DateTime (SQL Server 2005)

I can extract the month and day by using Day(Date()), Month(Date()). I cant extract hours, with HOUR(Date()). I get the following error. 'HOUR' is not a recognized built-in function name. How can I extract hours? ...