sql-server

T-SQL How To: Compare and List Duplicate Entries in a Table

SQL Server 2000. Single table has a list of users that includes a unique user ID and a non-unique user name. I want to search the table and list out any users that share the same non-unique user name. For example, my table looks like this: ID User Name Name == ========= ==== 0 parker Peter Parker 1 parker Mary...

does it makes sense to do SP for simple queries like select * from users

is it going to be faster if instead of doing select * from users where id = 1 or delete from users where id = 1 or select count(*) from users I would create a SP for it ? ...

Is there a combination of "LIKE" and "IN" in SQL?

Hi folks. In SQL I (sadly) often have to use "LIKE" conditions due to databases that violate nearly every rule of normalization. I can't change that right now. But that's irrelevant to the question. Further, I often use conditions like WHERE something in (1,1,2,3,5,8,13,21) for better readability and flexibility of my SQL statements. ...

Speed up this query joining to a table multiple times

Hi, I have this query that (stripped right down) goes something like this : SELECT [Person_PrimaryContact].[LegalName], [Person_Manager].[LegalName], [Person_Owner].[LegalName], [Person_ProspectOwner].[LegalName], [Person_ProspectBDM].[LegalName], [Person_ProspectFE].[LegalName], [Person_Signatory].[LegalNa...

How can I grant datareader to a sql role?

Is it possible to grant the datareader privileges to a SQL Server Database Role rather than a User? ...

Consuming RSS in MS SQL

Does anyone know of a way to consume RSS in MS SQL? ...

Interesting Row_Number() bug

I was playing with the Stack Exchange Data Explorer and ran this query: http://odata.stackexchange.com/stackoverflow/q/2828/rising-stars-top-50-users-ordered-on-rep-per-day Notice down in the results, rows 11 and 12 have the same value and so are mis-numbered, even though the row_number() function takes the same order by parameter as th...

Linq to SQL - Failing to update

Hello, I'm having some troubles with updating linq to sql entities. For some reason, I can update every single field of my item entity besides name. Here are two simple tests I wrote: [TestMethod] public void TestUpdateName( ) { using ( var context = new SimoneDataContext( ) ) { Item item = context...

send dbmail on @@error from sql server 2005

Hi, I am trying to send database mail when error occurs inside the transaction.My setup for dbo.sp_send_dbmail is correct , when I execute the proc I do get an email within 1 min. However when I try to use dbo.sp_send_dbmail inside another proc within transactions than I do not get the email. Sql server does show in the result window ...

sql server bulk copy out/postgres copy from infile

I'm starting a conversion of a system from MS SQL Server to Postgres. I have the table structures converted, and I use "bcp" to get the data out of SQL Server. ERROR: invalid byte sequence for encoding "UTF8": 0x80 HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is con...

SQL Server INSERT ... SELECT Statement won't parse

I am getting the following error message with SQL Server 2005 Msg 120, Level 15, State 1, Procedure usp_AttributeActivitiesForDateRange, Line 18 The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns. I have copy and pasted the select...

How can I tell if a SQL Server database is being backed up

Is there a way to programmatically determine if a SQL Server backup is currently being performd on a particular database? We have automated database backup scripts for both data and log files, where the databases are backed up nightly and log files are backed up every 15 minutes, 24 hours a day. However, we think that the log file back...

Instead of Triggers - Can they coexist with regular Triggers

Can Instead Of triggers co-exist with regular triggers? If so, are there any potential issues we should be aware of? ...

An expression of non-boolean type specified in a context where a condition is expected, near 'END'.

So maybe someone can point me in the right direction of what is causing this error? I've been fighting with this for a couple of hours and searching the web, and I can't figure out what I'm doing wrong here. It's included as part of a stored procedure, I don't know if that matters, if it does I can include that as well. Tables and fie...

Loop through non-integer rows using SQL

I know how to accomplish my task with .NET, but I wanted to do this just in SQL. I need to loop through all of the rows where the primary key is somewhat arbitrary. It can be a number or a series of letters, and probably any number of unusual things. I know I could do something like this... DECLARE @numRows INT SET @numRows = (SELECT ...

Error while trying to attach .mdf to a SQL Server Express 2008

The snapshot says is it all - I used to be able to attach a database, but after i detached today then tried to attach, i kept getting this error: http://img197.imageshack.us/img197/2574/attacht.jpg ...

Making one table equal to another without a delete *

Hey, I know this is bit of a strange one but if anyone had any help that would be greatly appreciated. The scenario is that we have a production database at a remote site and a developer database in our local office. Developers make changes directly to the developer db and as part of the deployment process a C# application runs and pro...

Is PDO for SQL Server support query contain Link Server

Is PDO for SQL Server support query contain Link Server ? I try using mssql_connect but it didn't work. I have try PDO but it alwas return error on query() method. ...

How to connect Visual Studio 2010 to sql server 2008

I need to make a questionary(test) from users then write their answers in a database, I want to make a test on a web page. Please, if somebody know please help me. ...

how can i get data from excel via "select statement" in sql 2005?

is there any method to get data from excel to sql ? i think that we can do without any writing C#codes. For example : select * from MyExcellFile.xls.Sheet1. Or may be any wizard in sql? ...