Separate words by group wise for each row in SQL

I have a string something like No People,Day,side view,looking at camera,snow,mountain,tranquil scene,tranquility,Night,walking,water,Two Person,looking Down And I have a table Group_words Group Category —————————————————————————————————————————————————————- ——————– No People,One Person,Two Person,Three Person,Four Person,five person,medium group of people,large group of people,unrecognizable person,real people People Day,dusk,night,dawn,sunset,sunrise Weather looking at camera,looking way,looking sideways,looking down,looking up View Angle I want to check […]

How to concat many rows into one string in SQL Server 2008?

This question already has an answer here: Concatenating Column Values into a Comma-Separated List 8 answers

Prompt for Database Connection String

I would like to offer a database connection prompt to the user. I can build my own, but it would be nice if I can use something that somebody else has already built (maybe something built into Windows or a free library available on the Internet). Anybody know how to do this in .Net? EDIT: […]

Table Valued Constructor Maximum rows limit in Select

I have a Table Valued Constructor through which am Selecting around 1 million records. It will be used to update another table. SELECT * FROM (VALUES (100,200,300), (100,200,300), (100,200,300), (100,200,300), ….. ….. –1 million records (100,200,300)) tc (proj_d, period_sid, val) Here is my original query : When I do the above select it is […]

MS Sql: Conditional ORDER BY ASC/DESC Question

I want to to make to make the ordering in my query conditional so if it satisfiess the condition it should be ordered by descending For instance: SELECT * FROM Data ORDER BY SortOrder CASE WHEN @Direction = 1 THEN DESC END

Get family members

Supose the families bellow: The Build Schema of this is: create table PersonConn (child int, parent int) insert into PersonConn values (1,2) insert into PersonConn values (1,3) insert into PersonConn values (5,3) insert into PersonConn values (5,4) insert into PersonConn values (6,7) insert into PersonConn values (6,8) insert into PersonConn values (2,9) insert into PersonConn […]

Delete data from dependent tables

Is there a query in SQL Server 2008 which will delete data from all dependent tables as well, along with the selected table? My apologies for not having elaborated on the question. I know that Cascade Delete would work fine, but my application connects to a 3rd party SQL Server db. I have a few […]

varchar or nvarchar

I am storing first name and last name with up to 30 characters each. Which is better varchar or nvarchar. I have read that nvarchar takes up twice as much space compared to varchar and that nvarchar is used for internationalization. So what do you suggest should I use: nvarchar or varchar ? Also please […]

1:1 Foreign Key Constraints

How do you specify that a foreign key constraint should be a 1:1 relationship in transact sql? Is declaring the column UNIQUE enough? Below is my existing code.! CREATE TABLE [dbo].MyTable( [MyTablekey] INT IDENTITY(1,1) NOT FOR REPLICATION NOT NULL, [OtherTableKey] INT NOT NULL UNIQUE CONSTRAINT [FK_MyTable_OtherTable] FOREIGN KEY REFERENCES [dbo].[OtherTable]([OtherTableKey]), … CONSTRAINT [PK_MyTable] PRIMARY KEY […]

How do aggregates (group by) work on SQL Server?

How does SQL Server implement group by clauses (aggregates)? As inspiration, take the execution plan of this question’s query: select p_id, DATEDIFF(D, MIN(TreatmentDate), MAX(TreatmentDate)) from patientsTable group by p_id Before query data, simple select statement and its execution plan is this: After retrieving the data with the query and execution plan:

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.