sql

NHibernate unexpected ORDER BY Statement

Hi, I am using NHibernate 2.0, and when I submit a request asking for the top 2 records to be returned, I get a number of ORDER BY clauses in my SQL. When I take out the Max results, the query looks fine (no ORDER BY statements). Why is NHibernate automatically adding this when I am looking for a subset of records? Thanks in advance ...

Npgsql & Postgresql : ERROR: XX001: could not read block 2354 of relation...

Hi, I have a service running and inserting data (a lot of data). Sometime, and this is only about few weeks, I receive this error: ERROR: XX001: could not read block 2354 of relation 1663/17633/17925: read only 0 of 8192 bytes. This error is from the Npgsql connector of PostGresql: Exception trace: at Npgsql.NpgsqlConnector.Chec...

SQL: Select As Columns

Hi I have a table with data in it as such: Cars: id | name ---------- 1 | Buick 2 | Honda 3 | Toyota What I would like to do in a Stored Proecdure is get the result like this: Temp Table: Buick | Honda | Toyota ---------------------- I realize it has no values, but I just want to get this part first. I am guessing this would in...

SQL Server: Creating table from stored schema?

I'd like to create a stored procedure that takes the name of table as a parameter, and then creates that table, if it doesn't exist, according to a schema stored somewhere. Is that possible--can I store a schema and use is as a template to create tables from? Or must I hard-code the CREATE TABLE and its scheme in the stored procedure it...

Should Dates be Stored as a Datetime or as an int in SQL?

I store all my dates for post in my forum in datetime (0000-00-00 00:00:00). I see that phpBB, punBB and all popular forums store dates in int? What is better? ...

Type 'Microsoft.SqlServer.Types.SqlHierarchyId' is not supported for identity members.

I'm getting the above exception while trying to read data from a table using Linq2Sql. Does anyone know what's happening here? ...

T-SQL: formatting "numeric" to format similar to c# style {0:#.00####}

Is there an easy way to format SQL Server numeric(18,6) data type to format similar to c#'s {0:#.00####} but in T-SQL? E.g. 12.550000 should produce 12.55. 14.456700 should produce 14.4567. 15.00 should produce 15.00. ...

SQL Query to Collapse Duplicate Values By Date Range

I have a table with the following structure: ID, Month, Year, Value with values for one entry per id per month, most months have the same value. I would like to create a view for that table that collapses the same values like this: ID, Start Month, End Month, Start Year, End Year, Value, with one row per ID per value. The catch is that...

Monitor SQL queries executed by a Delphi application

I'd like to monitor SQL queries executed by my application while it runs. I'm using a dbExpress connection to an Oracle 11g database under Delphi 2007. This used to be possible under the BDE with the sqlmon.exe utility. Is there a similar utility for dbExpress? I've tried the Toad SQL Monitor, which logs two or three queries and then...

Take advantage of multiple cores executing SQL statements

Hi I have a small application that reads XML files and inserts the information on a SQL DB. There are ~ 300 000 files to import, each one with ~ 1000 records. I started the application on 20% of the files and it has been running for 18 hours now, I hope I can improve this time for the rest of the files. I'm not using a multi-thread a...

How can I easily flatten this Sql Server heirarchy into an inherited inclusive list?

I have tables (for simplicity sake) as outlined below: Category -------------------- CategoryId (0 for root nodes) ParentCategoryId ProductCategory -------------------- ProductId CategoryId I'd like to be able to retrieve a distinct list of all categories and their inherited products (all the way back to category 0). Category 0 shou...

How do I expand comma separated values into separate rows using SQL Server 2005?

I have a table that looks like this: ProductId, Color "1", "red, blue, green" "2", null "3", "purple, green" And I want to expand it to this: ProductId, Color 1, red 1, blue 1, green 2, null 3, purple 3, green Whats the easiest way to accomplish this? Is it possible without a loop in a proc? ...

What if 2^32 is just not enough?

Hi, what if you have so many entries in a table, that 2^32 is not enough for your auto_increment ID within a given period (day, week, month, ...)? What if the largest datatype MySQL provides is not enough? I'm wondering how should I solve a situation where I'm having so many entries added to my table which require unique ID, but I fill...

SQL Query convert integer to hex and hex to integer

So I have this Query working (where signal_data is a column) in Sybase but it will not work with Microsoft SQL Server: HEXTOINT(SUBSTRING((INTTOHEX(signal_data)),5,2)) as Signal I also have it in Excel (where A1 contains the value): =HEX2DEC(LEFT(DEC2HEX(A1),LEN(DEC2HEX(A1))-2)) Does anyone know how I would do this in SQL? ...

Asp.Net select in Sql

This is going to be very simple I know. I have seen so many different ways of using sql in asp.net with no real standard. What I want to know is how to cleanly select from an sql database in asp.net and retrieve multiple records. For example: select all userids. String sql = "SELECT [UserId] FROM [UserProfiles] WHERE NOT [UserId] = '...

Sql Query not working!

INSERT INTO `test` (`x`, `y`) WHERE `id` = `$id` VALUES (`$x`, `$y`) Whats wrong with this query? I run this in a mysql_query() function in a php file. ...

SQL Server: Sanitizing @param against injection attacks

For the sake of argument, let's just say I have to create a local variable containing a SQL query that has an INSERT: DECLARE @insert NVARCHAR(MAX) SELECT @insert = 'INSERT INTO [dbo].[' + @table + '] VALUES... EXEC (@insert) This INSERT is also going to contain a column value: DECLARE @insert NVARCHAR(MAX) SELECT @insert = 'I...

SELECT DISTINCT

I'm working on an SSIS package where I'm importing data from a CSV file into a SQL table. The only field that I'm concern with is the Username. This Username must be unique. I don't care whether first name or last name are the same or not. In the package, I imported the data from file into a temp SQL table. And then I used SELECT DISTI...

SQL Server - An error occurred while executing batch. Error message is: The directory name is invalid.

Our database server had run out of disk space, after freeing up some disk space any query run in sql server management studio, with the results sent to grid view, resulted in this error: An error occurred while executing batch. Error message is: The directory name is invalid. When the results sent to text view the queries worked fine. ...

db2 storage error when running stored procs

I am seeing the above error when running a small number of stored procs in our application. The actual error that we get is sqlcode=-930, which according to the db2 documentation is: 'There is not enough storage available to process the statement.' Question: how can i increase the storage available to these procs? has anyone else enco...