sql-server

SQL Server Collation Conflict

Transferring data from one SQL server to another but when Schema is compared and syncronised the following error is received. We are using redgate SQL compare to complete. Cannot resolve collation conflict for equal to operation Base SQL server is SQL_Latin1_General_CP1_CI_AS and the destination server is Latin1_General_CI_AS ...

In SQL Server, is a sort by short substring more efficient than a sort by the entire, long field?

Consider the following SQL Server 2005/2008 query: Select [UID], [DESC] From SomeTable Order By [Desc]; If Desc is a fairly long field (Varchar(125) with many entries > 70 chars) and you don't need a strict sorting, would it would be more efficient to do this: Select [UID], [DESC] From SomeTable Order By Substring([Desc], 0, 20); T...

IIS 7 can't connect to SQLServer 2008

Sorry if this is the most seen question on the web, but this is my turn. I am trying to publish my asp.net mvc app on IIS 7 under MS Sql Server 2008. I am on a Windows Server 2008 virtual machine. I get the following classical error: A network-related or instance-specific error occurred while establishing a connection to SQL Serv...

SQL Server 2008 Windows Auth Login Error: The login is from an untrusted domain

When attempting to connect to a SQL Server 2008 Instance using Management Studio, I get the following error: Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. (Microsoft SQL Server, Error: 18452) I can login using SQL Authentication without problem. I've been getting this err...

Web users searching for too much data

We currently have a search on our website that allows users to enter a date range. The page calls a stored procedure that queries for the date range and returns the appropriate data. However, a lot of our tables contain 30m to 60m rows. If a user entered a date range of a year (or some large range), the database would grind to a halt....

Check Contraint Bypassing CATCH block in Distributed Transaction

Hello, I have a MSSSQL stored procedure performing a distributed transaction that looks like this: SET XACT_ABORT ON; SET NOCOUNT ON; BEGIN TRY BEGIN DISTRIBUTED TRANSACTION insert into LNKSRV.INST.dbo.zz (id, val) values (1, 'a'); insert into LNKSRV.INST.dbo.zz (id, val) values (2, 'b'); COMMIT TRANSACTION END TRY BEGIN C...

SQL Server: How do I add a constraint to an existing table but only if the constraint does not already exist?

I need to add a constraint to an existing SQL server table but only if it does not already exist. I am creating the constraint using the following SQL. ALTER TABLE [Foo] ADD CONSTRAINT [FK_Foo_Bar] FOREIGN KEY ([BarId]) REFERENCES [Bar] ([BarId]) ON UPDATE CASCADE ON DELETE CASCADE I'm hoping I can add some SQL to the begining of the...

How do I capture/log SQL Server 2005 "Attention" events?

This is in reference to this question here: http://stackoverflow.com/questions/546781/check-contraint-bypassing-catch-block-in-distributed-transaction Apparently in that distributed transaction scenario, an "attention event" is sent to our sql server and is destroying the connection without giving us the opportunity to log the error in...

IMultipleResult.GetResult<>() truncating result data

hi I am calling a stored procedure using Linq2Sql, and the sp returns a long xml string as the result, from a select statment. I'm using IMultipleResults.GetResult<>() to retrieve the string. Everyting is fine except when the Xml string is too long, and the GetResult returns only a partial output. Is there any constraint on IMultiple...

Using MS SQL Server 2005, how can I consolidate detail records into a single comma separated list

BACKGROUND:I am running MS2005. I have a MASTER table (ID, MDESC) and a DETAIL table (MID, DID, DDESC) with data as follows 1 MASTER_1 2 MASTER_2 1 L1 DETAIL_M1_L1 1 L2 DETAIL_M1_L2 1 L3 DETAIL_M1_L3 2 L1 DETAIL_M2_L1 2 L2 DETAIL_M2_L2 If I join the tables with SELECT M.*, D.DID FROM MASTER M INNER JOIN DETAIL D on M.ID = D.MID I...

Compare current date with stored datetime using month an year only

Hi there. Using SQL Server 2005 I have a field that contains a datetime value. What I am trying to do is create 2 queries: Compare to see if stored datetime is of the same month+year as current date Compare to see if stored datetime is of the same year as current date There is probably a simple solution but I keep hitting brick wal...

Search by parameter only if user enters a value

I want to rewrite this query so that if @UserName gets passed in a null value then it leaves the Client_User out of the search criteria. I only want it to search by name if the user enters a name in the username textbox on the webform. I'm not sure how to do this. select * from weblogs.dbo.vwlogs where Log_time between @BeginDate and...

SSIS/VB.NET Equivalent of SQL IN (anonymous array.Contains())

I've got some SQL which performs complex logic on combinations of GL account numbers and cost centers like this: WHEN (@IntGLAcct In ( 882001, 882025, 83000154, 83000155, 83000120, 83000130, 83000140, 83000157, 83000010, 83000159, 83000160, 83000161, 83000162, 83000011, 83000166, 83000168, 83000169, 82504000, 82504003, 8250400...

Long query prevents inserts

I have a query that runs each night on a table with a bunch of records (200,000+). This application simply iterates over the results (using a DbDataReader in a C# app if that's relevant) and processes each one. The processing is done outside of the database altogether. During the time that the application is iterating over the results...

Querying a timestamp column from LINQ to SQL

My table has a timestamp column named "RowVer" which LINQ maps to type System.Data.Linq.Binary. This data type seems useless to me because (unless I'm missing something) I can't do things like this: // Select all records that changed since the last time we inserted/updated. IEnumerable<UserSession> rows = db.UserSessions.Where ( usr => ...

SQL Date Search without time

I have a query that searches by date. the dates in the database include the time. How do I search on just the date only. select * from weblogs.dbo.vwlogs where Log_time between @BeginDate and @EndDAte and (client_user=@UserName or @UserName Is null) order by Log_time desc cmd.Parameters.AddWithValue("@BeginDate", txtBeginDate.Text...

Does BETWEEN with dates actually work in SQL SERVER 2008

According to cdonner, in his answer here and on his blog. He claims that BETWEEN with date yields inconsistent results From his blog: select case when '9/1/08' between '9/1/08' and '9/15/08' then 'in' else 'out' end as s1, case when '9/1/08' between '8/28/08' and '9/1/08' then 'in' else 'out' end as s2 s1 s2 ---- ...

finding max possible date in ms sql server 2005+

is there a function like getdate() in ms sql server 2005 that let's you get the max possible date? i do NOT want to find the highest date in a table. i want to get the max possible date that sql server will be able to store. basically, i want an expiration date of never ...

efficient way to make paging on sql server 2008

hi there, i'm using sql server 2008, asp.net mvc and linq. Should i use LINQ skip and take method for paging, or do my self paging sql query script which way more efficient than ...

What does "Is Identity" column property mean in SQL Server?

I am using SQL Server for the first time and I see that a column property is called Is Identity. What doeds this mean? What are the advantages of marking a column property as Is Identity = Yes ? Thanks in advance. ...