Create “Default Values or Binding” for new coumn having Data-Type of DateTimeOffset(7)?

When you create a new table in the database and you added a new column, having data-type of DateTimeOffset(7). What do you use as “Default Values or Binding” for this DateTimeOffset as default? Thanks..

TVP vs loop for each parameter

I am in a situation where I need to do some comparison for some products that are in a shopping cart. The cart can have as many items as the user desires but the average over time is roughly 5-15 items per cart. My question is one about optimization/overhead. I need to check what department […]

SQL MIN Datetime based on first occuranceof a value in another column

This is what I have ID Name DateTime Value Group 1 Mark 1/1/2010 0 1 2 Mark 1/2/2010 1 1 3 Mark 1/3/2010 0 1 4 Mark 1/4/2010 0 2 40 Mark 1/5/2010 1 2 5 Mark 1/9/2010 1 2 6 Mark 1/6/2010 1 2 7 Kelly 1/1/2010 0 3 8 Kelly 1/2/2010 1 3 […]

Fixed VS Flexible roles in DB

I was reading an article at There I read Let’s say you have two sets of database user one programmers and the other DBA’s. The programmers should be able to fire insert, update and delete queries while DBA’s should be able to create database, backup and do maintenance related activities. But DBA’s should not […]

Sql query delete all Comments in all Topics which created by an special Username

I have two tables in my sql server 2008 TOPIC(idtop,title,usercreated); COMMENT(idcom,content,idtop,usercom); In my delete account function, I have to delete all the topics created by that account and all the comments in each topic. So first, I have to delete all comments of all topics which created by an special user (usercreated) but I really […]

Set 24 hours TimeInterval in Where Clause of SQL server

I need to query a table in an sql server, in which the Query results to be filtered between yesterday’s 5:00Pm to Today’s 5:00PM. But the Table contains Date and Time in seperate fields. Any help would be appreciated. Thanks

Retrieve data from a For XML subquery

I am creating a table as follows: CREATE TABLE dbo.Test ( A int, B int ) GO INSERT INTO Test VALUES (1, 11) GO INSERT INTO Test VALUES (5, 55) GO INSERT INTO Test VALUES (4, 44) GO I have a query which converts this into XML as : SELECT A,B FROM Test ORDER BY […]

Get single value from dynamic SQL SELECT

How can I retrieve the value from the following dynamic SQL and assign it to a variable? SET @SQLString = N’SELECT TOP 1 D’+CAST(DAY(@dateTime)AS varchar(MAX)) + ‘ FROM TabelForMonthCurrent’ + ‘ WHERE empContractID=’ + CAST(@pEmpContractID AS nvarchar(MAX)) + ‘ AND Year=’ + CAST(YEAR(@dateTime) AS nvarchar(MAX)) + ‘ AND Month=’ + CAST(MONTH(@dateTime) AS nvarchar(MAX))

SQL using GROUP BY or DISTINCT to get back first records

I have a table like this: group id 1 10 1 11 1 12 2 13 3 14 I want to get back the first record of each group, so my table should return something like this: group id 1 10 2 13 3 14 What’s the best way to do this in SQL?

dynamic SQL adding base on above row

I want to generate Col A, Col B, Col C from my database SQL Server… I want to dynamically populate Col C base on the row above it Col C = ( Col A + Col B + Col C [Above] )… I draw an example incase my explanations wasnt clear enough Please Help…

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