sql-server

Question on Converting ints to datetimes in TSQL

I have a stored procedure that takes an int for the desired month and year as parameters. It uses these to compare some datetime values from the tables I'm pulling from. I need to conver them into DateTime values. I'm trying to do something like this: CONVERT(DATETIME, CONVERT(varchar(4), @year) + '-' + Convert(varchar(2),@month) + '-01...

SQL - Counting and Summarizing (in ranges) the number of instances of a given transaction

I've got an Occurrences table that contains one row for each time a user took an action. A user take an action multiple times per day. It looks like this: Date Username ------ -------- 1/1/9 User1 1/1/9 User1 1/1/9 User2 1/2/9 User1 1/2/9 User3 1/3/9 User1 1/3/9 User1 1/3/9 User1 1/3/9 User2...

Equivalent of LIMIT and OFFSET for SQL Server?

In PostgreSQL there is the Limit and Offset keywords which will allow very easy pagination of result sets. What is the equivalent syntax for Sql Server? ...

Querying for tables & columns named as keywords

Assume SQL Server 2005+. Part A: What is the canonical way to query from the system/internal/meta/whatever tables/views (sorry, not a database ninja) for any user table or column names that use SQL Server keywords (like case)? I don't mind maintaining the list of keywords if that's not query-able, as it only changes with versions of S...

SQL Query execution shortcut OR logic?

I have three tables: SmallTable (id int, flag1 bit, flag2 bit) JoinTable (SmallTableID int, BigTableID int) BigTable (id int, text1 nvarchar(100), otherstuff...) SmallTable has, at most, a few dozen records. BigTable has a few million, and is actually a view that UNIONS a table in this database with a table in another databas...

Altering a on attribute data size from a table in SQL Server

So I'm trying to do something I thought would've been straightforward. I have a table in the DB named "Images." It's 'Description' property is of type nvarchar(50). I simply want to make it nvarchar(250). Every time I try, it says it can't save because some tables would have to be redropped. I can't just delete it (i think) because, ther...

Recommended Overview Book specifically on SQL Server 2005

I need a good overview book on SQL server 2005. I'm trying to move from SQL server 2000/DTS to SQL server 2005/SSIS. I've searched around on safari and most books seem to be about a specific part of SQL Server 2005 or a particular principle. I'm wondering if anyone can specifically recommend a solid book that covers the following areas ...

Null value being returned from a Stored Procedure using Linq to SQL

If I run a stored procedure in my database (SQL 2000) and return the SCOPE_IDENTITY, I receive a value. However, using LINQ to SQL, I get a null value for the Column1 property. Anyone have a suggestion? ...

Sql Server CE 2.0 RDA on IIS 7 and Sql Server 2008

I am trying to get SQL server CE 2.0 RDA that was working on IIS6 (Server 2003) and Sql Server 2000 moved to a Windows 2008 server with IIS and SQL server 2008. Is this something that is possible? It seems that there is no fundamental reason that it would not. The target database is not changed since the migration. My first problem i...

primary key duplicate record bypass to next insert

weird question. i am inserting 10,000 records or so in a table and the primary key is not an Identity field. so when inserting all 10,000 if some are duplicate, is there a way to skip to next record in sql server insert and make sure the non-duplicates go in? i really dont care bout the duplicates not getting inserted. ...

Sql Server 2008 Cross-database table linking (relationships)

Hi guys, I have a bit of an issue, and to be honest I don't think there's an answer, but I'll give it a try anyway. So I have two databases [A]->Company and [B]->Product. Both databases have a Country table which is then linked to other tables in each individual database. The problem is that the data between the two Country tables is a ...

silverlight 5 feature request list?

Does anyone know the location of silverlight 5 feature request list? If there isnt one, shall we start it right here? Ability to embed silverlight applications in Powerpoint presentations. Sql server compact edition for silverlight. ...

[C#] how to query sql server database size

When writing C# code, if I can manage to get a SqlConnection, is there any way to perform a query to get the size of the Database? I searched the internet, seems "sp_spaceused" can be used, but it is not a table, it is a procedure. Can I query a procedure? ...

Linq to SQL Audit Trail / Audit Log: should I use triggers or doddleaudit?

Hi, I'm working on a business app that requires that ALL database transactions be audited (for legal purposes mainly). I've looked around the web and came across DoddleAudit (http://www.codeplex.com/DoddleAudit) which basically adds the ability for Linq to SQL to track the changes. Much like people use Interceptors in Hibernate. The th...

How to reference one CTE twice?

I have a very fat common table expression which includes row numbers so that I can return a paged result set. I also want to return the total number of records that match the query before I page the result set. with recs as (select *, row_number() over (order by id) as rownum from ......) select * from recs where rownum between @a and @...

SQL Query Source Code

Hi all, I have 3 tables. One table has all the people, [Pat], each with a unique [PatId]. The second table has all the insurance company information, [Ins], each with a unique [InsId]. The third table has the patient insurance info, [PatIns]. In the [PatIns] table, some patients (also [PatId]) have secondary or 3rd insurance and it deno...

How to view the calls the sql server receives in live mode?

Hi, Is there any tool, or any VS debug option i'd use to watch all the calls my c# application, sends to the SQL server 2k8? I'd like to know how efficient is my c# code at doing the calls, like how many SELECTS is it sending at certain time/situation. Thanks. ...

T-SQL: what COLUMNS have changed after an update?

OK. I'm doing an update on a single row in a table. All fields will be overwritten with new data except for the primary key. However, not all values will change b/c of the update. For example, if my table is as follows: TABLE (id int ident, foo varchar(50), bar varchar(50)) The initial value is: id foo bar ----------------- 1 ...

Create several Procedure in one notepad

I am using vb.net and in my project i want to create store procedure in single sql file but system reads as single procedure..So like this is an sql file.. create proc aa ... ... create proc bb ... ... for to solve this problem what can i do ? Please forward me the solution as soon as possible. ...

Why Error: "[ODBC Driver Manager] Data source name not found..."? (works fine on dev environment)

I'm encountering problems in my ASP page. This is a login page which checks the user's credentials to the database before it allows access to the main page. I created a debugger page to find out what's the error details and this is the error message: Microsoft][ODBC Driver Manager] Data source name not found and no default driver speci...