sql-server

How to quote and reference SQL Server table and field names

Good day! Despite the fact LINQ2SQL and ADO.NET Entity Framework exists there were situations when I need to revert to plain old DataSet (not typed) and friends. While writing SQL for SqlCommand: Is it needed to quote field and table names with []? Is it good to prefix table names with [dbo] I use to use this syntax: SqlCommand co...

Multiple IN statements for WHERE. Would this return good data?

SELECT ['VISA CK - 021810$'].[ACCT NBR #1], ['VISA CK - 021810$'].[ALT CUST NM #1], ['VISA CK - 021810$'].[LAST USED] FROM ['VISA CK - 021810$'] WHERE ['VISA CK - 021810$'].[ALT CUST NM #1] IN ( SELECT ['VISA CK - 021810$'].[ALT CUST NM #1] FROM ['VISA CK - 021810$'] GROUP BY ['VISA CK - 021810...

What is the Datatype for 10:00 AM PST in SQL Server

Hi I have a table that need to store Timeslot such as 10:00 AM PST, 10:15 AM PST.... etc at a constant interval of 15 Min. I am wondering if there is any Time datatype available for this kind of data? I need to store them as 11:00 AM PST, 11:15 AM PST, 11:30 AM PST, 11:45 PM PST, 12:00 PM PST, 12:15 PM PST, 12:30 PST, 12:45 PM PST, 01...

How to handle when SSRS does not automatically update fields based on database query?

So I am trying to change the number of fields in my dataset in SSRS and the refresh button is not picking up the added field from the SQL server. The query is definitely returning the correct data, as I have double checked in the server engine itself. Also, I have tried manually adding the field using the SSRS menu, but as soon as I exec...

Best way to Sort-n-Concatenate 5 columns

!!! WARNING !!! Dearest SQL expert, please keep reading before to start to scream. this uber-denormalized table structure is obtained after apply some combinatories-sugar upon a nicely normalized set of data : ). I'm avoiding to renormalize this resultset because I want to keep simple the complete process (also this...

Deadlock Problem because of an Update Lock.

We have a deadlock issue we're trying to track down. I have an deadlock graph (xdl) generated from Profiler. It shows the losing SQL statement as a simple Select statement, not an Update, Delete or Insert statement. The graph shows the losing Select statement as requesting a Shared lock on a resource **but also owning an Update lock on a...

How can an improvement to the query cache be tracked?

I am parameterizing my web app's ad hoc sql. As a result, I expect the query plan cache to reduce in size and have a higher hit ratio. Perhaps even other important metrics will be improved. Could I use perfmon to track this? If so, what counters should I use? If not perfmon, how could I report on the impact of this change? ...

Cross Join 'n' times a table

It is possible to write a generic function/procedure/select/somethingElse to cross-join a table against himself 'n' times? (yes, 'n' is a given parameter : ) How would you do it? Example Having this table: Value ------- 1 2 3 cross join it 2 times, would return: Value | Value ------------------ 1 1 1 ...

Performance difference if I UNION first, then put WHERE on unioned result set?

In Microsoft SQL, is there any difference in performance between this: SELECT columns FROM table1 WHERE cond UNION SELECT columns FROM table2 WHERE cond and this: SELECT columns FROM ( SELECT columns FROM table1 UNION SELECT columns FROM table2 ) WHERE cond ? ...

Is adding a bit mask to all tables in a database useful?

A colleague is adding a bit mask to all our database tables. In theory this is so we can track certain properties of each row across the entire system. For example... Is the row shipped with the system or added by the client once they've started using the system Has the row been deleted from the table (soft deletes) Is the row a defaul...

best sql server client tool and refresh managment studio edit window ?

After using other gui tools for databases like oracle sql developer , plsql editor ..., I am not quite comfortable with sql server management studio,so I want to ask: Is there any better client tools for sql server? In management studio ,if I've already opened edit window, how to refresh the data in the window ? ...

Efficiency of checking for null varbinary(max) column ?

Using SQL Server 2008. Example table : CREATE table dbo.blobtest (id int primary key not null, name nvarchar(200) not null, data varbinary(max) null) Example query : select id, name, cast((case when data is null then 0 else 1 end) as bit) as DataExists from dbo.blobtest Now, the query needs to return a "DataExists" column, t...

SQL server datetime column filter on certain date or range of dates

There is an example for today here http://stackoverflow.com/questions/2583228/get-row-where-datetime-column-today-sql-server-noob I am primarily interested in 2008 only. For today it looked like SELECT (list of fields) FROM dbo.YourTable WHERE dateValue BETWEEN CAST(GETDATE() AS DATE) AND DATEADD(DAY, 1, CAST(GETDATE() AS DATE)...

Sql string adding problem

SELECT a.one + ' test ' +b.two from table1 a right join table1 on a.id =b.id The problem is that when one is null then it the whole string is null, is there some kind of trick to bypass this problem msSQL 2005 ...

How can I use SQL Server's full text search across multiple rows at once?

I'm trying to improve the search functionality on my web forums. I've got a table of posts, and each post has (among other less interesting things): PostID, a unique ID for the individual post. ThreadID, an ID of the thread the post belongs to. There can be any number of posts per thread. Text, because a forum would be really boring ...

SQL Server - Percent based Full Text Search

Hi I want to conduct search on a particular column of a table in such a way that returning result set should satify following 2 conditions: Returning result set should have records whose 90% of the characters matches with the given search text. Returning result set should have records whose 70% of the consecutive characters matches wi...

Finding which table a constraint belongs to

Hi, I need to find out which table(name) a particular constraint belongs to. Does anyone have any TSQL to achieve this? ...

Delphi: how to efficently read a big binary file, converting it to hexadecimal for passing it as a varbinary(max) parameter?

I need to convert a binary file (a zip file) into hexadecimal representation, to then send it to sql-server as a varbinary(max) function parameter. A full example (using a very small file!) is: 1) my file contains the following bits 0000111100001111 2) I need a procedure to QUICKLY convert it to 0F0F 3) I will call a sql server funct...

Scope of Derived Tables in SQL Server

I've been looking into SQL recently and exploring a bit. in regards to Temp Tables I have discovered 3 different temp table types: 1) CREATE TABLE #TempTable 2) DECLARE TABLE @TempTable 3) SELECT * FROM (SELECT * FROM Customers) AS TempTable Now I understand the scope behind the #TempTable and the @TempTable types, but what about the...

SQL Server Management Studio hangs on 100% during recovery

Hello, I want to restore a bak file in SQL server 2008 (the backup was created on a SQL server 2005). I set the recovery to WITH NORECOVERY, as I want to apply further transaction logs later. Meaning: the database should stay in restore mode, but the recovery-dialog in the management studio does not finish ever. It shows 100% for nearly...