sql-server-2008

Is it possible to get the user who last edited a stored proc, function, table or view in SQL Server?

I'm not even sure SQL Server stores this kind of information, but, is it possible to get the username of the person who last modified a particular stored procedure, function, table or view? Nothing critical, just wondering. Thanks! ...

Bizarre performance issue: Common Table Expressions in inline User-Defined Function

Here's a brain-twister for the SQL guys - can anyone think of a reason why the first of these functions performs fine, and the second one runs dog-slow? Function A - Typically finishes in ~5 ms CREATE FUNCTION dbo.GoodFunction ( @IDs UniqueIntTable READONLY ) RETURNS TABLE AS RETURN SELECT p.ID, p.Node, p.Name, p.Level FROM...

SQL Server 2008: Count Number of Keys In Multiple Date Ranges

SQL Server 2008 again. I have a primary key pt_id and a datetime column order_dts for each id. I want to count the number of keys in each year from 1996-2008 and return eight results - a count for each year. For a single year SELECT COUNT pm.pt_id AS '1996' FROM dm.medications pm WHERE (pm.order_dts BETWEEN '1/1/1996' and '12/31/1996') ...

how to allow full-text search to include lookup tables for SQL server 2008 ?

Suppose I have following two tables: Employee(Name, description, departiemtID,...) --foreign key: departmentID Department(departmentID, name, description, ...) I want to full-text search on Employee.Name, Employee.description, department.Name, department.description. What's the best solution for this case? Demo query please. ...

How to synchronize SQL Server 2008 database with SQL Server 2005 database?

I am using VS 2008 Team Suite and SQL Server 2008 in my development environment. I am deploying to a shared-host website with shared-host SQL Server 2005. I want to push changes from my development environment to my production host. I tried using Data | Schema Compare... and it reports to me that it does not support SQL Server 2008. W...

Pros and Cons of Triggers vs. Stored Procedures for Denormalization

When it comes to denormalizing data in a transactional database for performance, there are (at least) three different approaches: Push updates through stored procedures which update both the normalized transactional data and the denormalized reporting/analysis data; Implement triggers on the transactional tables that update the seconda...

SQL Server 2008: Count Number of Keys In Multiple Date Ranges Across Multiple Tables

Thanks to the people who answered my question this morning: http://stackoverflow.com/questions/2087664/sql-server-2008-count-number-of-keys-in-multiple-date-ranges This is an extension of it and I'm not clear how to generalize the previous solutions to this case. The database I'm working with has medications, lab values, and diagnoses...

Visual Web Dev 2008 & SQL Server Express 2008; not working together?

So....I am a rookie at this so if I missed something simple, please excuse me, but I don't know. So i downloaded Visual Web Developer 2008, SQL Server Express 2008, etc, and I am trying to learn how to use SQL Server, and create .aspx web pages, etc. So one of the first things I tried was the Hello world (C#) ine Web Dev and it worked ...

SQL Server 2008 & Visual Web Developer 2008 express editions: Connection to DB Fail!

So I saw this question/comment... http://stackoverflow.com/questions/1625991/how-to-integrate-sql-server-2005-express-edition-to-visual-web-developer-2008-exp/1626114#1626114 And this is EXACTLY what I am having trouble with, only using SQL Server 2008 express edition and Visual Web Dev 2008 express. Everytime I try to click to add a ...

varchar(max) everywhere?

Is there any problem with making all your Sql Server 2008 string columns varchar(max). My allowable string sizes are managed by the application. The database should just persist what I give it. Will I take a performance hit by declaring all string columns to be of type varchar(max) in Sql Server 2008, no matter what the size of the da...

SQL Server: Add Columns When In Production Environment

Are there any issues/problems related to adding new columns (not indexed) into a table when the database is already online. Assume that the database is quite busy on a constant basis and the table in question has over 1'000'000 records. Thanks. ...

How to elegantly write a SQL ORDER BY (which is invalid in inline query) but required for aggregate GROUP BY?

I have a simple query that runs in SQL 2008 and uses a custom CLR aggregate function, dbo.string_concat which aggregates a collection of strings. I require the comments ordered sequentially hence the ORDER BY requirement. The query I have has an awful TOP statement in it to allow ORDER BY to work for the aggregate function otherwise th...

How to make a user function deterministic

I'm trying to achieve optimization based on deterministic behavior of a user defined function in SQL Server 2008. In my test code, i'm expecting no extra function calls dbo.expensive, since it's deterministic and called with same argument value. My concept does not work, please explain why. What could be done to achieve the expected op...

SQL Job: How to start with ?

Can anyone help me to create an SQL job in SQL server Agent (SQL 2008) ,which will run in a purticular time interval(Ex: Daily) and select records from a table with status=1 (select name,age from student)and pass to another stored procedure which accepts student name and age ...

Moving a Point along a Path in SQL Server 2008

I have a geography field stored in my database, holding a linestring path. I want to move a point n meters along this linestring, and return the destination. For example, I want the destination point 500 meters along the linestring starting from its beginning. Here's an example -- what is the YourFunctionHere? Or, is there another w...

SQL Server - alter column - adding default constraint

I have a table and one of the columns is "Date" of type datetime. We decided to add a default constraint to that column Alter table TableName alter column dbo.TableName.Date default getutcdate() but this gives me Incorrect syntax near '.'. Does anyone see anything obviously wrong here, which I am missing (other than having a better...

How I select a table sorted as a "Queue"?

I need to select a table sorted as a "Queue", the least recent to most recent row. Exists something feature that enable me to do this? ...

In SQL, how do I allow for nulls in the parameter?

I have what seems to be a really easy SQL query I can't figure out and its driving me nuts. This is SQL 2008. Basically, there is a status field where the can pick "pending", "satisfied" or all. If they send in "pending" or "satisfied" there's no problem. But when they pick all I'm having problems. Mostly because I can't figure out how ...

SQL Server 2008 CLR vs T-SQL: Is there an efficiency/speed difference?

I'm a C# developer who has done some basic database work in T-SQL. However, I need to write a very complicated stored procedure, well above my T-SQL knowledge. Will writing a stored procedure in C# using the .net CLR as part of SQL Server 2008 cause my stored procedure to be less efficient than if it were written in T-SQL? Is the differ...

While pulling the rows from the SQL server view needs to update a table based on some condition

I have a requirement to pull some table(let say table A) data by using a view. In that case based on some condition, I need to update the table A and will return the rows from that table. Please let me know if anybody knows the solution for this... ...