All Questions

289
votes
9answers
151188 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 signif...
1258
votes
24answers
1540712 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 tmpB...
132
votes
11answers
157861 views

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

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 delimi...
931
votes
12answers
1096436 views

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

I need to update this table in SQL Server 2005 with data from its 'parent' table, see below: sale id (int) udid (int) assid (int) ud id (int) assid (int) sale.assid contains the correct value...
36
votes
6answers
28095 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? 1.>------------- SqlCommand cmd = new SqlCommand("INSERT IN...
49
votes
10answers
65219 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 create...
332
votes
14answers
359500 views

Get top 1 row of each group

I have a table which I want to get the latest entry for each group. Here's the table: DocumentStatusLogs Table |ID| DocumentID | Status | DateCreated | | 2| 1 | S1 | 7/29/2011 | | 3| ...
121
votes
31answers
395675 views

How to calculate age (in years) based on Date of Birth and getDate()

I have a table listing people along with their date of birth (currently a nvarchar(25)) How can I convert that to a date, and then calculate their age in years? My data looks as follows ID Name ...
475
votes
8answers
629474 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.Manufac...
140
votes
7answers
361343 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...

Previous Next