sql

MS Access Convert like function to Memo Data Type

I need to use rich text formatting for a field in a report in MS Access in order to use character spacing. In the report, attempting to change the Text Format in the field's properties from Plain Text to Rich Text Produces the error: "The setting you entered isn't valid for this property." I presume that is because the field is not a mem...

How can I make the Entity Framework generated SQL cleaner

I am using the Entity Framework with SQL Server Express 2008. When using the profiler, I see SQL being generated like this: SELECT [Project1].[C1] AS [C1], [Project1].[EmployeeID] AS [EmployeeID], [Project1].[FirstName] AS [FirstName], [Project1].[LastName] AS [LastName], [Project1].[Active] AS [Active], [Project1].[Updated] AS [U...

How do I sanitize SQL without using prepared statements

For some sql statements I can't use a prepared statment, for instance: SELECT MAX(AGE) FROM ? For instance when I want to vary the table. Is there a utility that sanitizes sql in Java? There is one in ruby. ...

Using PIVOT in SQL Server 2008

Let's say I have some data, either in a SQL Server 2008 table or a [table]-typed variable: author_id review_id question_id answer_id 88540 99001 1 719 88540 99001 2 720 88540 99001 3 721 88540 99001 4 722 8...

Adjusting Timezone - Convert XML DateTime to SQL DateTime

We are using TypedDataSet in our application. Data is passed to procedure in form of XML for insert/update. Now after populating DE with data, datetime remains the same though timezone information is added as below. Date in DB: 2009-10-29 18:52:53.43 Date in XML: 2009-10-29T18:52:53.43-05:00 Now when I am trying to convert below XML...

Optimizing for an OR in a Join in MySQL

I've got a pretty complex query in MySQL that slows down drastically when one of the joins is done using an OR. How can I speed this up? the relevant join is: LEFT OUTER JOIN publications p ON p.id = virtual_performances.publication_id OR p.shoot_id = shoots.id Removing either condition in the OR decrea...

Grouping Query Help in sql server 2005?

My table TEST has the following rows: test | 1 test | 2 test | 3 How I query it to get the following result? test | 1 - 2 - 3 ...

Converting/Searching GETUTCDATE()

If I store all my dates in SQL Server 2005 as GetUtcDate() what is the best way to search on these date fields. I'm using C# so should i convert the date submitted by the user to UTC using C# (passing to Stored Proc) to search my dates in SQL? Also, since i'm using UTC do I need to worry about day light savings? When I want to display ...

What's the Maximum Value of smallint(6) unsigned in MySQL?

What's the Maximum Value of smallint(6) unsigned in MySQL? ...

SQL Timeout Error

I am getting a sqlserver Timeout in my aspx page. It comes when i click one of the link in the website. Will indexing will help with this problem? Thanks ...

How to write the SQL for the following problem?

I have to find, if there is any row in the table for which value of col2 is duplicate. Like in the specified scenario row 1 and 2 are duplicate as value of col2 is same. Table ------------------- Col1 Col2 Col3 1 1 4 2 1 3 3 2 2 4 3 1 At present what i am doing is select count(*) from table...

php mysql_insert_id on multiple rows?

Hi, Is it possible to get the auto incremented ids from a query which inserts multiple rows? eg: INSERT INTO table (col1, col2) VALUES (1, 2), (3, 4), (5, 6); Alteratively, is there a way to find the NEXT auto increment value WITHOUT inserting anything into the table? Thanks ...

Performance of sql Count*

asp.net and sql server, have sqls for selecting a subset of rows, I need the count* frequently Of course I can have a select count(*) for each of these sqls in each roundtrip but soon it will become too slow. -How do you make it really fast? ...

Convert XML to table in SQL Server 2005.

If I pass in an xml parameter to a stored proc which looks like this: <ClientKeys> <ck>3052</ck> <ck>3051</ck> <ck>3050</ck> <ck>3049</ck> ... </ClientKeys> ...and then convert the XML to a temp table like this: CREATE TABLE #ClientKeys ( ClientKey varchar(36) ) INSERT INTO #ClientKeys (ClientKey) SELECT Param...

Mapping .Net decimal with large number of fraction to SQL Server

If I have a decimal like 32.593170731707329023999999999 - what SQL Datatype, and precision and scale should I use? My integer parts are pretty small (1-10000) and fraction part big. Have tried decimal with different variations of precision and scale, but get an overflow exception in .Net. ...

Pretty format sql in .NET code, performance?

Hi, Will the compiler optimize pretty formatted strings, or will that code run slower than strings that are not divided in a readable way? for example string sql = "select * " + "from person " + "where id = :id"; or string sql = "select * from person where id = :id"; This is just a small example. You know how complicate...

How to display all but first table row?

Is it possible to display all but first row from a table in sql server 2005? I have this data: --------------------------------- | ID | Name | --------------------------------- | 1 | John Smith | | 2 | John Doe | | 3 | John Thatcher | --------------------------------- In ...

SQL: deleting data where parent doesn't exist

I have a hierarchical table 'pages', with 'id' and 'id_parent' fields. Thanks to some crappy old code there are still a lot of rows without a parent. I want to delete these rows. Is this possible using only SQL? ...

SQL SELECT with m:n relationship

I have m:n relationship between users and tags. One user can have m tags, and one tag can belong to n users. Tables look something like this: USER: ID USER_NAME USER_HAS_TAG: USER_ID TAG_ID TAG: ID TAG_NAME Let's say that I need to select all users, who have tags "apple", "orange" AND "banana". What would be the most effective way t...

SQL Performance using a COALESCE Function

Hi, I have a SQL Query with a join between several tables. When I run this query it takes 1min 12 however if I add a Coalesce around the accountID I get a massive performace benefit and it runs in 12 minutes. See the full unedited query below. SELECT dbo.CaptionMapItem.CaptionMapItemID, dbo.CaptionMapItem.NodeText, ...