sql-server

Can I return a byte array from a SQL Server VarBinary column using a parameterized query?

I wrote a small VBA procedure to test uploading and downloading of files as binary data into and out of a VarBinary column in SQL Server using ADO. The upload process appears to work, but I cannot get the download process to work. I believe the output parameter for VarBinary is setup incorrectly, but I cannot find any documentation on h...

TSQL to find if logins have password same as loginname?

Hi I want to check if SQL logins have passwords same as thier login name. E.g. login name 'abc123' has password= 'abc123'. I need to do this for a security audit across many 2000 and 2005 servers. Is it possible to check using TSQL? Thanks in advance ...

Is there any performance issue using Row_Number to implement table paging in Sql Server 2008?

I want to implement table paging using this method: SET @PageNum = 2; SET @PageSize = 10; WITH OrdersRN AS ( SELECT ROW_NUMBER() OVER(ORDER BY OrderDate, OrderID) AS RowNum ,* FROM dbo.Orders ) SELECT * FROM OrdersRN WHERE RowNum BETWEEN (@PageNum - 1) * @PageSize + 1 AND @PageNum * @PageSiz...

Fluent NHibernate issue with nvarchar(max) and sql express 2005

I have recently updated from NH2.1 to the latest trunk build. I also upgraded to the latest source code of Fluent NHibernate. A new issue has been introduced which manifests as the following exception : System.Data.SqlClient.SqlException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. P...

Inserting a values with condition.

Using SQL Server 2005 I want to insert a table with where condition Table1 column Name - ID, Name, Dept, Rank Query Insert into table1 values('1', 'Raja' 'IT', 'True') where Rank <> 'False' Need Query Help ...

Subtract minute from datatime in sql server 2005

Suppose I have a datetime field whose value is 2000-01-01 08:30:00 and a duration field whose value is say 00:15( meaning 15 minutes) If I subtract these two, I should get 2000-01-01 08:15:00 I am trying like SELECT DATEDIFF(minute, '00:15','2000-01-01 08:30:00'); But the output is 52595055. How can i get the desired result. N.B...

How do you PIVOT on a Bit datatype in SQL Server?

This is probably a very simple question. All I want to really do is to make the column into a row whose data type is a bit. SUM, MIN, MAX doesn't work on bits. COUNT works but I really don't want to count. I just want to move all the stuff from columns into rows like if I took a pair of scissors, cut the information and moved it -90...

Is there a way to replicate some data not all data in db by sql server replication?

I want to replicate some of data that exists in my database. I want to replicate specified data. Is there a solution? ...

Can't store a korean string in database using LINQ

I'm using this code to store korean string in my database: Dim username As String = Request.QueryString.Get("Some Korean String") Using dg As New DataContext() Dim newfriend As New FriendsTable With {.AskingUser = User.Identity.Name, .BeingAskedUser = username, .Pending = True} dg.FriendsTables.InsertOnSubmit(newfriend) dg.SubmitChanges...

causing deadlock issue in sys.sp_grantdbaccess in SQL Server 2008

I am facing deadlock issue in the System SP sys.sp_grantdbaccess. Has anyone faced the same issue. If yes, please let me know to overcome this issue. ...

Is there a way to force replication that replicate only inserted and updated data?

I want to have a version of my db that contains all of data from first to now. If I use sql server replication, can I force that to ignore delete operation for replication? ...

Connection timeout in ODBC

I know that I can set the connection timeout for MS SQL Server when using ADO or OLE DB, by adding Connect Timeout=somevalue to the connection string. This doesn't seem to work for ODBC connections though. Specifically, we made the decision to use the standard SQL Server ODBC driver that ships with Windows XP (SQLSRV32.DLL version 2000....

Optimizing delete for a table referenced by lots of foreign keys

I have a table Document that is referenced by a ton of other tables via foreign keys. I am trying to delete a Document record, and according to my execution plan, SQL Server is doing a clustered index scan on every one of the referencing tables. This is very painful. I thought having a FK automatically made an index on the FK fields? ...

Best way to deploy new index to very large table in SQL Server 2008

I have a database in production with one table that has grown extremely large (lots of accumulated data). To improve query performance I used the sql server optimizer which suggested a new index. So I made a copy of the production database to test against and it does improve performance, however my problem is that it took about 24 hou...

Script to add an index on each foreign key?

Seeing as a foreign key does not automatically create an index in SQL Server, I want to create an explicit index on every FK field in my database. And I have over 100 tables in the schema... So, does anyone have a ready packaged script that I could use to detect all FKs and create an index on each? ...

'LINQ query plan' horribly inefficient but 'Query Analyser query plan' is perfect for same SQL!

I have a LINQ to SQL query that generates the following SQL : exec sp_executesql N'SELECT COUNT(*) AS [value] FROM [dbo].[SessionVisit] AS [t0] WHERE ([t0].[VisitedStore] = @p0) AND (NOT ([t0].[Bot] = 1)) AND ([t0].[SessionDate] > @p1)',N'@p0 int,@p1 datetime', @p0=1,@p1='2010-02-15 01:24:00' (This is the actual SQL taken from SQL Pr...

Prevent T-SQL statement from committing application started transaction

I am writing a program that uses ADO.NET's SqlCommand to execute a number of user provided batches of T-SQL statements. My application opens a transaction in which all of the statements are executed to ensure that if there is an error executing any, the whole lot are rolled back. The problem I have come across is that a badly placed CO...

Sql Server Collation

The book I am reading says that SQL Server supports two kinds of character data types—regular and Unicode. Regular data types include CHAR and VARCHAR, and Unicode data types include NCHAR and NVARCHAR. The difference is that regular characters use one byte of storage for each character, while Unicode characters require two bytes per ...

What is the difference between ; and GO in stored procedure in SQL Server ?

What is the difference between ; and GO in stored procedure in SQL Server ? Actually, if I have a stored procedure in SQL server and wanna to put t separate queries inside it which the first one just calculates number of records (count) and the second one selects some records based on some conditions, then what sould I use between that ...

BI Projects in Visual Studio when SQL Server is in a different machine

Hello, I've visual studio 2005 installed in one machine (dev machine) and SQL Server 2005 installed in another machine. But only when we install SQL Server with SSRS, we get the Business Intelligence Project templates in Visual Studio. Now having SQL Server in another machine how can i create a report server project in VS 2005 in the ...