sql

Storing JSON in an SQL Server database?

I'm developing a form generator, and wondering if it would be bad mojo to store JSON in an SQL Server database? I want to keep my database & tables simple, so I was going to have `pKey, formTitle, formJSON` on a table, and then store {["firstName":{"required":"true","type":"text"},"lastName":{"required":"true","type":"text"}} in...

code duplication in sql case statements

Hi I'm trying to output something like the following but am finding that there is a lot of code duplication going on. | australian_has_itch | kiwi_has_itch | | yes | no | | no | n/a | | n/a | no | ... My query looks like this with two case statements tha...

MySQL - Selecting how many "Days Old" a field is.

How can I select how many days old a field is based on it's "DateAdded" field? E.g.: SELECT DAYSOLD(tbl_stuff.DateAdded) as DaysOld FROM tbl_stuff ...

Oracle SELECT TOP 10 records

Hi, i have an big problem with an SQL Statement in Oracle. I want to select The TOP 10 Records ordered by STORAGE_DB wich arent in a list from an other select statement. This one works fine for all records: SELECT DISTINCT APP_ID, NAME, STORAGE_GB, HISTORY_CREATED, TO_CHAR(HISTORY_DATE, 'DD.MM.YYYY') AS HISTORY_DATE ...

Case Order by using Null

Hello I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT 4 INSERT INTO #Foo SELECT NULL INSERT INTO #Foo SELECT 2 INSERT INTO #Foo SELECT 5 INSERT INTO #Foo SELECT 1 SELECT * FROM #Foo ORDER BY CASE WHEN Foo IS NULL THEN Foo DESC ELSE Foo END DROP TABLE #Foo I'm trying to produce the following o...

Querying for names

I have a table (say "Demographics") on SQL Server. In this table are the following columns "LastName", "FirstName", "MiddleName", "Prefix" , "Suffix". I have one textbox to search for them on a webpage. My question: Whats a good design strategy for queries where the user could be searching for various combinations of names including las...

Implement Partial sorted query in sql server 2005

I have to show records in such a way that some selected records should come first. After this, another records come in sorted manner from the same table. For example, If I select state having stateID = 5 then the corresponding record should come first. after this another records should come in sorted manner. For this, I tried union but...

Programmatically Create a Full Text Population Schedule via TSQL

Hi All, I have a SQL 2005 TSQL script which sets up my FT Catalog and Indexes, but I would like to also create a Population schedule for these indexes via the same Code, can anyone point me in the right direction. Thank you Matt ...

Oracle: set timezone for column

Hi, I need to do migration date->timestamp with timezone similar to described here: http://stackoverflow.com/questions/1664627/migrating-oracle-date-columns-to-timestamp-with-timezone. But I need to make additional convertion (needed to work correctly with legacy apps): for all dates we need to change timezone to UTC and set time to 12:...

SQL Reporting Services Daylight saving time query

I have been tasked with writting a report from MS Dynamic CRM. The report contains appointment and account information. I am using Visual Studio 2005 and SQL 2005. The problem I have found is that if an appointment has a scheduled start date that falls after Britsh Summer Time but has a creation date before (BST) then the ScheduledStart...

Union Distinct rows but order them by number of occurrences in mysql

Hi I have the following query: SELECT o.id,o.name FROM object o WHERE ( o.description LIKE '%Black%' OR o.name LIKE '%Black%' ) UNION ALL SELECT o2.id,o2.name FROM object o2 WHERE ( o2.description LIKE '%iPhone%' OR o2.name LIKE '%iPhone%' ) Which procude the following: id name 2 ...

How to calculate End and start Week?

how does one calculate the beginning of a week from a given date e.g 23 March 2010 beginning of the week is 21 March 2010 ...

How to export Oracle statistics

Hi, I am writing some new SQL queries and want to check the query plans that the Oracle query optimiser would come up with in production. My development database doesn't have anything like the data volumes of the production database. How can I export database statistics from a production database and re-import them into a development...

mysql Command timeout error

I am converting my database from sql server 2005 to mysql using asp .net mvc. I have bulk data in sql server(around 4 lakh records), But i am facing command timeout/wating for comand timeout error which when i search on google can be given 65535 as its highest value Or can be given 0 if someone wants that comand should wait for unlimite...

How to filter MySQL SELECT by an aggregate function?

SELECT h11, HA11 FROM florin.h11 WHERE (3>d1 AND 3<d2) OR (3>d1 AND 3=d2 AND id=MAX(id)) UNION (3=d1 AND 3<d2 AND id=MIN(id)); Here a screenshot of my table stucture: ...

MySQL optimized sentence

I have a simple table where I have to extract some records. The problem is that the evaluation function is a very time-consuming stored procedure so I shouldn't to call it twice like in this sentence: SELECT *, slow_sp(row) FROM table WHERE slow_sp(row)>0 ORDER BY dist DESC LIMIT 10 First I thought in optimize like this: SELECT *, sl...

How to find the worst performing queries in SQL Server 2008?

How to find the worst performing queries in SQL Server 2008? I found the following example but it does not seem to work: SELECT TOP 5 obj.name, max_logical_reads, max_elapsed_time FROM sys.dm_exec_query_stats a CROSS APPLY sys.dm_exec_sql_text(sql_handle) hnd INNER JOIN sys.sysobjects obj on hnd.objectid = obj.id ORDER BY max_logical_r...

Does unique on a temporary table column create an index?

I have a temporary table that I'm using and I have a unique column, example:myID INT UNIQUE Would this create an index on that column? Or do I have to explicitly create the index? ...

C# : DBConnection.Open() timeout is too long.

Hi, I'm trying to connect to a server that the user inputs. When the server doesn't exist, I'd like to give a quick feedback to the end-user so he can correct what he's typed. Is there any way to test if a server exists before trying to connect ? Thanks ...

Data refresh and drill down problem with SSAS cube and excel services

I have a SSAS cube which I am using in an excel document, prepare a report which has drill-down etc and i am publishing it to a sharepoint site. It gets published alright but when I try to drill down it throws an error "Data Refresh failed" etc.The data source and the sharpoint site are on the same machine(running windows server 2008) an...