sql-server

Formatting link lists using TSQL

Shog9 keeps on making my link lists look awesome. Essentially, I write a bunch of queries that pull out results from the Stackoverflow data dump. However, my link lists look very ugly and are hard to understand. Using some formatting magic Shog9 manages to make the link lists look a lot nicer. So, for example, I will write a query t...

Formatting Numbers in SQL Server

How can I format the number 123.45678 to 123.45 in SQL Server 2008? ...

How to Merge SQL Query(Help required)

Dear friends, below are my two SQL queries: select distinct a_bm.DestProvider_ID, a_bm.DestCircel_ID, convert(datetime,dbo.fnToDate(a_bm.BM_BillFrom),103) as fromdate, convert(datetime,dbo.fnToDate(a_bm.BM_BillTo),103) as todate, t_rec.TapInRec as BillRecevable, t_rec.TapInRec as Billreceied from Auditdata_Bill...

How do I JOIN aggregations results from several SQL SELECTS?

I have a MEMBERS table with the following relevant columns: Name JoinDate Level --1=Gold,2=Silver,3=Bronze** I want to create a single query to return a membership summary that lists the total number who joined by year and by membership level. Basically, the columns in my resultset would be something like this: | YEAR | ...

Update function in TSQL trigger

I have a question about TSQL function Update. For example, I have a table with a field Name. If I check if the field Name is changed or not in a After Update trigger likes this: if Update(Name) Begin -- process End Will the Update still return TRUE even if Name is not changed? The following update statement will update it wi...

How to get datatable as a result of stored procedure

hi guys, Following is my stored procedure. ALTER PROCEDURE SP_GetModels ( @CategoryID bigint ) AS BEGIN Select ModelID,ModelName From Model where CategoryID=@CategoryID END and i am calling stored procedure in code behind as public SqlConnection conn; public SqlDataReader GetModels() { DataTable d...

delete selected rows in table ( How do i increase the speed )

Back story i have a table that stores cached times, and currently has about 1m rows. And when i update the table with new versions of the cached items i need to delete the old cached items ( About 3k items ). Its not critical that these items are deteted right away but i would prefere it, as when clients get out cached items i would like...

Subsonic 3, SimpleRepository, SQL Server: How to find rows with a null field?

How ca I use Subsonic's Find<T> method to search for rows with a field containing the "null" value. For the sake of the discussion, let's assume I have a c# class called "Visit" which contains a nullable DateTime field called "SynchronizedOn" and also let's assume that the Subsonic migration has created the corresponding "Visits" table a...

How do you concat multiple rows into one column in SQL Server?

I've searched high and low for the answer to this, but I can't figure it out. I'm relatively new to SQL Server and don't quite have the syntax down yet. I have this datastructure (simplified): Table "Users" | Table "Tags": UserID UserName | TagID UserID PhotoID 1 Bob | 1 1 1 2 ...

History tables pros, cons and gotchas - using triggers, sproc or at application level.

I am currently playing around with the idea of having history tables for some of my tables in my database. Basically I have the main table and a copy of that table with a modified date and an action column to store what action was preformed eg Update,Delete and Insert. So far I can think of three different places that you can do the hi...

What is a Trusted Connection?

What is a trusted connection in terms of SQL Server 2005 (Trusted vs Windows Auth)? ...

What data type is best for storing comments in SQL Server?

What is an effective datatype in SQL 2005 to store a comments field? ...

Why not always use GUIDs instead of Integer IDs?

What are the disadvantages of using GUIDs? Why not always use them by default? ...

When do triggers fire and when don't they.

Pretty general question regarding triggers in SQL server 2005. In what situations are table triggers fired and what situations aren't they? Any code examples to demonstrate would be great. I'm writing a audit based databases and just want to be aware of any situations that might not fire off the triggers that I have set up for update,...

Third Party Tracing Tools for Sql Server

Apart from Sql server profiler ,is there any third party user friendly tool available to trace sql server objects? ...

Hows does a large transaction log affect performance?

Hi to all, I have seen that our database has the full recovery model and has a 3GB transaction log. As the log gets larger, how will this affect the performance of the database and the performance of the applications that accesses the database? JD ...

Linq-to-Sql NotSupportedException: Can I be sure it will work on a newer server version ?

I am doing a small reporting project that needs to read a lot of data from an SQL Server 2000 database. I am using Linq-to-SQL; and when I run one of my queries, I get this Exception: NotSupportedException: Cannot translate expression to SQL for this server version This message indicates that my query will work on a newer server versi...

SQL Server triggers "For Each Row" equivalent

I need to update multiple rows in a Parts table when a field in another table changes and I want to use a trigger. The reason for the trigger is many existing application use and modify the data and I don't have access to all of them. I know some databases support a For Each Row in the trigger statement but I don't think Microsoft does. ...

Asp.net tableadapter insert not returning correct identity value

In my VS2008 asp.net web page codebehind I am calling an add routine in a SQL tableadapter, as follows: NewLabID = LabItem.AddLaborItem(ThisWONum, TechID, DateTime.Now, DateTime.Now, "Working", ""); The record is being added correctly, but 'NewLabID' returns 1 every time, not the actual new LabID (LabID is defined as int/identity). Th...

storing images in sql server

I am trying to put together db design for storing images. Many of you might have had experience designing db to store images and the challenges associated with it. The db might store hundreds of thousands of images eventually. I am planning to use SQL Server 2008 db and entity framework. Planning to use FILESTREAM datatype for storing ...