sql-server

How to solve TimeOut Expired Problem?

Using SQL Server 2005 and VB6 When I executing for yearly data or more than 3 months' data, it is showing "Timeout Expired" error. It is not executing completely. My Connection String ConnectionString = "Provider=SQLOLEDB.1;" & _ "Persist Security Info=False; " & _ "User ID=" & Settings.SQL_Username & _ "; Password = " & S...

Running a batch file to update a field with strange character in SQL Server DB

I have a table called Field in my SQL Server database. The table has a field called "Units". I have a batch script which inserts a lot of things into here using OSQL and one of the things entered is the pound sign (£). When OSQL runs the queries, it converts the £ sign to -ú instead. What I need to have is a separate batch file which ...

Re-Sequence a set of data in SQL Server

I have a table of values like this: CREATE TABLE ( Name1 VARCHAR (50), Name2 VARCHAR (50), Sequence INT ) In this table I have rows like this 'Bob', 'Jones', 1 'James','Ant', 2 I want the best way to UPDATE (UPDATE SET) sequence based on the order of say the Name2 column, so when re-sequenced the values are: 'James','...

How to get a particular attribute from XML element in SQL Server

I have something like the following XML in a column of a table: <?xml version="1.0" encoding="utf-8"?> <container> <param name="paramA" value="valueA" /> <param name="paramB" value="valueB" /> ... </container> I am trying to get the valueB part out of the XML via TSQL So far I am getting the right node, but now I can not figure...

SQL Server Templates - How Do I Escape The Less Than Character?

I like to use SQL Server 2005 templates to run frequently used queries. You can include parameters in your templates using this syntax: <LastName, varchar, 'Bob'> I have a query that needs the less than or equals to operator <= but unfortunately the SQL Server 2005 template interprets that as the start of a parameter. I have been unab...

SQL Server 2000: search through out database

Some how some records in my table are getting updated with value of xyz in a certain column. Out of hundred of stored procedures, functions, triggers, how can I determine which code is doing this action. Is there a way to search through the database some how through each and every script of the code? Please help. ...

SQL Double-Outer Join??

I have two tables A and B... A and B can be joined by a common column. A and B will have some rows that match on the join column. But A has some rows that B doesn't have, and B has some rows that A doesn't have. A LEFT OUTER JOIN from A to B will give all rows in A, filling in NULLS for the B columns that couldn't be matched. A R...

How to Calculate Median?

I need to calculate a median on a set of data, so I created a temp table and have tried to follow some articles online with zero success, here is what I am working with: CREATE TABLE #QuizTemp (QuizProfileID INT,Cnt INT,TotalScore INT) INSERT INTO #QuizTemp SELECT QuizAnswers.QuizProfileID, COUNT(QuizAnswers.QuizProfileID) AS Cnt, SUM(...

Functions in SQL Server 2008

Does sql server cache the execution plan of functions? ...

Can you do a partial restore to an ms crm db?

Is there any way (3rd party product or other method) to do a partial restore to ms crm? Say a user accidentially deleted an account. Is there anyway to restore just that single account and corresponding notes, activities etc? We limit users' permissions but inevitably they will have permission to delete some things and will want to ...

How can I get a JSON object from a SQL Server table?

I have a view that I want to be converted into JSON. What is the SQL that I can use to produce on the server the JSON string needed to be returned? ...

Control flow in T-SQL SP using IF..ELSE IF - are there other ways?

I need to branch my T-SQL stored procedure (MS SQL 2008) control flow to a number of directions: CREATE PROCEDURE [fooBar] @inputParam INT AS BEGIN IF @inputParam = 1 BEGIN ... END ELSE IF @inputParam = 3 BEGIN ... END ELSE IF @inputParam = 3 BEGIN ... END END Is there any other ways? For example, in C...

SQL Server dynamic column list in contains function

I have a database table in SQL Server 2008 with 5 nvarchar(max) columns. We're using the CONTAINS function to look for text in these columns. We can look in all five columns using this kind of query: SELECT * FROM SomeTable ST WHERE CONTAINS( (ST.ColumnA, ST.ColumnB, ST.ColumnC, ST.ColumnD, ST.ColumnE) , '"Strawberry"') Now we want ...

one-to-many query selecting all parents and single top child for each parent

There are two SQL tables: Parents: +--+---------+ |id| text | +--+---------+ | 1| Blah | | 2| Blah2 | | 3| Blah3 | +--+---------+ Childs +--+------+-------+ |id|parent|feature| +--+------+-------+ | 1| 1 | 123 | | 2| 1 | 35 | | 3| 2 | 15 | +--+------+-------+ I want to select with single query every row fro...

(SQL) Grouping by End of week

I have a report which needs to total up the number of registrations per week, over the last ten weeks and display it as "Week Ending October 10th, 2009" 500" "Week Ending OCtober 3rd, 2009" 400" "Week Ending September 26, 2009" 1000" etc... Here is my query: SELECT Count(*) as [Total] ,Week = DateAdd(day, -1 * da...

DateTime in SSAS

I have a DateTime column in my Time dimension table. I want to display this as just MM/DD/YYYY and hide the time component (which is 00:00:00 anyways). How do I do this? ...

SQLServer data in PHP loses multibyte characters

I have PHP talking to SQLServer through ODBC using FreeTDS and unixODBC. I followed tutorials to get this setup. It's working fine now although special characters in the database are not showing up correctly. Specifically, the ™ symbol. It's showing up in the browser as �. I've tried setting client charset = UTF-8 in the [global] se...

Can I upgrade SQL Server express to Standard version on different machine

If I have a new install of SQL Server Standard on one machine, can I easily import my database from SQL Server Express on another machine? I was planning to detach the db transfer the file and attach on new machine. Is this the easiest way? What about permissions? Will this work? ...

do spaces in sql tables fubar queries?

I'm having an issue I'm generating sudoku puzzles and the solution to the puzzle are being stored in this format: xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx 8 spaces between the 9 sets, I cannot seem to query the row, it returns a blank row.. Is this because there is spaces? If I do a sel...

Change @prmMax from asp.net into SQL-server Query?

(Editor's note, I have attempted to translate and format more appropriately. See below for the original) I want to make an SQL query to get those "ACTIVATED WITHIN 28 DAYS AFTER REGISTRATION" and those "ACTIVATED ABOVE 28 DAYS AFTER REGISTRATION". How can I fix this query? Below this query is for GET THOSE "ACTIVATED WITHIN 28 DAYS AF...