Tag: sql-server-2008-r2

How to Group records by DateRange

How to group records by date range in sql ? Conside this Table Structure. Key ID VISITDATE 1 1 2011-01-07 2 1 2011-01-09 3 2 2011-01-10 4 1 2011-01-12 5 3 2011-01-12 6 1 2011-01-18 7 2 2011-01-21 9 1 2011-02-28 10 2 2011-03-21 11 1 2011-01-06 12 1 2011-02-29 I need to get the […]

Error while deploying SSAS after modifying dimension & attribute properties

I have created a cube that worked fine when deploying. After a added another dimension and altered some attribute properties it didn´t want to deploy no more.. I have some warnings but at least the ones that starts with “Dimension”… are old ones and didn´t do anything with first deployment. I have done some searching […]

Constant for database name in SQL Server

In my database creation script I have many lines like ALTER DATABASE [database_name_value] SET… because there is often need to create few instances with different names I often have to replace database_name in text editor and this is error-prone I would like to do it more properly by declaring some constant like database_name_constant and assign […]

History of commands on SQL Server

This query gives me the history of commands executed on SQL Server: Select * From ( SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query] FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest ) x When I added Where x.Query LIKE ‘%Insert%’ I get bad results (I think that this is because of the cross join): […]

SQL Server Getting First & Last Row that makes up aggregation

I have a Table that stores data on price movement over a minute. Each record contains the last Minute’s Open, High, Low, Close & Volume CREATE TABLE TimeBar ( Instrument varchar(20), BarTimeStamp datetimeoffset(7), Open decimal(18, 5), High decimal(18, 5), Low decimal(18, 5), Close decimal(18, 5), Volume int ) What I am trying to do is […]

Using timestamp from sqlserver in entity framework to only get changes rather then reloading whole table/view

I would like to have optimized version of my WinForms C# based application for slower connections. For this reason I wanted to introduce timestamp column into all tables (that change) and load most of things the first time it’s needed and then just read updates/inserts/deletes that could have been done by other people using application. […]

Create Job To Convert Data With SSIS

I Want To Convert Data From OldDatabase To NewDatabase Each Day By SSIS. for this: 1- Create Script From Exists New DataBase 2- Change DatabaseName OF Generated Script and Then Execute Script To Create NewDatabase2 whit no data. 3- Set SSIS Configuration Parameters. 4- Execute SSIS Package to convert Data. I Want to do this […]

JBoss AS 7 Datasource to SQL Server using Windows Integrated authentication

The title is pretty explanatory. I need to configure a datasource in JBoss AS 7 that will connect to a SQL Server 2008 R2 database using windows integrated. I have searched a lot but all the examples just use SQL authentication.

SQL Server 2008 R2 – Seemingly conflicting joins cause query to be very slow

This query takes 16 seconds to run SELECT WO.orderid FROM WebOrder as WO INNER JOIN Addresses AS A ON WO.AddressID = A.AddressID LEFT JOIN SalesOrders as SO on SO.SO_Number = WO.SalesOrderID If I comment out either of the joins, it runs in a small fraction of a second. Example: SELECT WO.orderid FROM WebOrder as WO […]

Why can't I truncate a table that is being referenced by a FK constraint?

So I’m trying to understand why SQL Server 2008 R2 complains when I try and truncate the table. I have 2 tables: Parent (id, ..) Child (id, parent_id, ..) The child table as a FK constraint (parent_id) to the Parent table. Now if I try and do: truncate table Child truncate table Parent It gives […]

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