tsql

Get the last day of the month in SQL

I need to get the last day of the month given a date in sql. If I have the first day of the month I can do something like this: dateadd(day, dateadd(month,'2009-05-01',1), -1) But does anyone know how to generalize it so I can find the last day of the month for any given date? ...

debug ssis package - reload InnerPackage.dtsx

Hi all, I used the wizard to build a package that loops through my tables does whatever. It has worked forever and now I have to change it. How on earth do I debug this thing? When I try to run it from bids, it opens InnerPackage.dtsx for editing and then asks me if I want to reload it (since it has changed since the last iteration o...

Whats the best SQL Query to get Related Items?

I have a small site where I want to get Related Videos on basis of Tags... what could be the best MS SQL 2005 query to get related Videos on basis of Tags. If you can give LINQ query that would be awsome. Here is Database Schema: CREATE TABLE Videos (VideoID bigint not null , Title varchar(100) NULL, Tags varchar(MAX) NUL...

Best SQL 2005 Query to get Related Items?

I have a small video site where I want to get related videos on the basis of the most matched tags. What would be the best MSSQL 2005 query to get the related videos? A LINQ query would be appreciated as well. Schema: CREATE TABLE Videos (VideoID bigint not null , Title varchar(100) NULL, isActive bit NULL ) CREATE T...

Continue after primary key violation error

The problem is during inserting data from staging table during import routine. The system is a legacy one I inherited, and short term while I develop something more suitable I want to patch things to avoid the data transfer failing. Unfortunately the facility exists via another application to create an entry into table, called CommRece...

How do I combine/merge columns from two SQL query results?

I have a set of data in a table named BWHourlyReadings, for example: ServiceID Hour InputOctets OutputOctets ========= ==== =========== ================= 27222 1 383088 804249 27222 2 270529 688683 27222 3 247251 290124 ... up to 24 hours of data 27222...

how to figure out which columns in the fact table are used for calculating measures in an OLAP cube?

I have to verify that olap cube data and the data from relational tables from where a cube is built is correct. And I will do so by writing the TSQL queries and compare the values with that of cube. But, I got stuck in the course of determining which columns are used for measure. How do I figure out which columns are used for measures?...

what is the easy way to compare cube data with that of data mart?

I was trying to compare with the cube's data with that of data mart using TSQL query. It s hard for me to find where the columns used in the cube are coming from. Because the columns used in the cube are coming from data source view, but how do I know which table? Help appreciated ...

SQL Server Login Configuration and Automation

What's a good way to manage and maintain SQL Server logins, server roles, and individual access rights across multiple databases that exist in multiple environments? What are your best practices? Some info about my situation: SQL Server 2005 We have N amount of "client" databases with identical schemas (in theory, at least) We have a ...

Getting MIN Price in Subquery in SQL Server (using DISTINCT)?

Hi there, I am trying to get a Minimun price from a car in a table i have.. I am using DISTINCT SELECT DISTINCT datepart(year,[Registration]) AS YearRegistered, MIN(SalePrice), Model, Make FROM [VehicleSales] But its not working, for example without distinct returns many car makes and models so i use distinct so i get unique ca...

using MIN on a datepart with Group BY not working, returns different dates

Hi there, Can anyone help with an aggregate function.. MIN. I have a car table that i want to return minimum sale price and minimum year on a tbale that has identical cars but different years and price ... Basically if i removed Registration (contains a YEAR) from the group by and select the query works but if i leave it in then i get...

Entity SQL compare datetime without milliseconds

I'm trying to fetch some records from MSSQL DB using EntityObject with EntitySQL query. The field i'm using to filter is type of datetime. The generated query projected without millisecond, to the SQL Server returns nothing. When i'm adding the milliseconds, i get results. How can i use the EntitySQL to get result without the millisecon...

Group records and put results into single field

I have the following recordset: ID AssetName 882 Training Room VCR 882 Training Room DVD 882 Training Room TV 858 Training Room VCR 858 Training Room Computer 858 Training Room TV I want to group each ID and get a resultset as such: ID Assets 882 Training Room VCR<br/>Training Room DVD<br/>Training Room TV 858 Training Room...

Periodic restarting auto numbering for SQL Server

I have a requirement for a program I'm working on to store job numbers as YY-###### with incrementing numbers starting at 000001 in each year preceded by the last two digits of the year. The only method I've been able to come up with is to make a CurrentJob table and use an identity column along with the last two digits of the year an...

Enabling TCP/IP protocol through t-sql script?

How to enable tcp/ip through t-sql script on sql server 2008? ...

Looking for exercises to learn SQL, using the Northwind database

I am trying to become more familiar with SQL by writing queries against the Northwind database. I am looking for some exercises that would help me to learn SQL and features of SQL Server. It is important that the exercises have solutions, and in complicated cases, it would be great if there was an explanation for the query. Thanks ...

what happens to the resultset if the lookup table in the lookup task is empty?

Will there be any further resultset to process if the lookup table in the lookup task is empty? sagar ...

Best way to filter hierarchical data using T-SQL?

Table1 has a list of items. Table2 has a list of groups the items can be associated with. Table3 is a cross-reference between 1 and 2. The groups in table 2 are set up in hierarchical fashion. Key ParentKey Name 1 NULL TopGroup1 2 NULL TopGroup2 3 1 MiddleGroup1 4 2 Middle...

How can I tweak this SQL to perform the arithmetic calculation only once

Say I have a query like this: select ((amount1 - amount2)/ amount1) as chg from t1 where ((amount1 - amount2)/ amount1) > 1 OR ((amount1 - amount2)/ amount1) < 0.3 Is there a way I can perform the arithmetic calculation only once instead of doing it thrice as in the above query ? EDIT: I am not sure if the datab...

T-SQL WHERE col IN (...)

I'm doing Select * From table Where Col IN (123,123,222,....) If I put more than ~3000 numbers in the IN clause SQL throws and error. Does anyone know if there's a size limit or anything?!! Thank you. ...