Skip to main content

Questions tagged [sql-server-2005]

Use this tag for questions specific to the 2005 version of Microsoft's SQL Server.

376 votes
12 answers
194k views

Simulating group_concat MySQL function in Microsoft SQL Server 2005?

I'm trying to migrate a MySQL-based app over to Microsoft SQL Server 2005 (not by choice, but that's life). In the original app, we used almost entirely ANSI-SQL compliant statements, with one ...
DanM's user avatar
  • 7,137
1846 votes
35 answers
2.6m views

Insert results of a stored procedure into a temporary table

How do I do a SELECT * INTO [temp table] FROM [stored procedure]? Not FROM [Table] and without defining [temp table]? Select all data from BusinessLine into tmpBusLine works fine. select * into ...
Ferdeen's user avatar
  • 21.6k
139 votes
11 answers
188k views

T-SQL: Opposite to string concatenation - how to split string into multiple records [duplicate]

Possible Duplicate: Split string in SQL I have seen a couple of questions related to string concatenation in SQL. I wonder how would you approach the opposite problem: splitting coma delimited ...
kristof's user avatar
  • 53.6k
1643 votes
19 answers
2.2m views

How can I do an UPDATE statement with JOIN in SQL Server?

I need to update this table in SQL Server with data from its 'parent' table, see below: Table: sale id (int) udid (int) assid (int) Table: ud id (int) assid (int) sale.assid contains the ...
Ant Swift's user avatar
  • 20.8k
86 votes
12 answers
140k views

What is the best way to create and populate a numbers table?

I've seen many different ways to create and populate a numbers table. However, what is the best way to create and populate one? With "best" being defined from most to least important: Table created ...
KM.'s user avatar
  • 103k
73 votes
6 answers
63k views

How do parameterized queries help against SQL injection?

In both queries 1 and 2, the text from the textbox is inserted into the database. What's the significance of the parameterized query here? Passing txtTagNumber as a query parameter SqlCommand cmd = ...
sqlchild's user avatar
  • 8,968
819 votes
13 answers
1.2m views

SQL update query using joins

I have to update a field with a value which is returned by a join of 3 tables. Example: select im.itemid ,im.sku as iSku ,gm.SKU as GSKU ,mm.ManufacturerId as ManuId ,mm....
Shyju's user avatar
  • 217k
259 votes
10 answers
326k views

Referring to a Column Alias in a WHERE Clause

SELECT logcount, logUserID, maxlogtm , DATEDIFF(day, maxlogtm, GETDATE()) AS daysdiff FROM statslogsummary WHERE daysdiff > 120 I get "invalid column name daysdiff". Maxlogtm is a ...
user990016's user avatar
  • 3,328
292 votes
16 answers
686k views

Select top 10 records for each category

I want to return top 10 records from each section in one query. Can anyone help with how to do it? Section is one of the columns in the table. Database is SQL Server 2005. I want to return the top ...
jbcedge's user avatar
  • 19.3k
1438 votes
31 answers
1.9m views

Check if table exists in SQL Server

I would like this to be the ultimate discussion on how to check if a table exists in SQL Server 2000/2005 using SQL Statements. Here are two possible ways of doing it. Which one is the standard/best ...
Vincent's user avatar
  • 22.7k
51 votes
2 answers
93k views

Retrieving last record in each group from database - SQL Server 2005/2008

I have done some seaching by can't seem to get the results I am looking for. Basically we have four different management systems in place throughout our company and I am in the process of combining ...
RyanF's user avatar
  • 513
248 votes
10 answers
701k views

How to update two tables in one statement in SQL Server 2005?

I want to update two tables in one go. How do I do that in SQL Server 2005? UPDATE Table1, Table2 SET Table1.LastName='DR. XXXXXX', Table2.WAprrs='start,stop' FROM Table1 T1, Table2 ...
Jango's user avatar
  • 5,485
141 votes
10 answers
168k views

SQL Server IN vs. EXISTS Performance

I'm curious which of the following below would be more efficient? I've always been a bit cautious about using IN because I believe SQL Server turns the result set into a big IF statement. For a large ...
Randy Minder's user avatar
312 votes
13 answers
1.0m views

INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server

Msg 547, Level 16, State 0, Line 1 The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Sup_Item_Sup_Item_Cat". The conflict occurred in database "dev_bo", table &...
SmartestVEGA's user avatar
  • 8,771
616 votes
18 answers
881k views

Insert multiple rows WITHOUT repeating the "INSERT INTO ..." part of the statement?

I know I've done this before years ago, but I can't remember the syntax, and I can't find it anywhere due to pulling up tons of help docs and articles about "bulk imports". Here's what I want to do, ...
Timothy Khouri's user avatar

15 30 50 per page
1
2 3 4 5
197