sql-server-2005

DECODE( ) function in SQL Server

SELECT PC_COMP_CODE, 'R', PC_RESUB_REF, DECODE(PC_SL_LDGR_CODE,'02','DR','CR'), PC_DEPT_NO DEPT, '',--PC_DEPT_NO, PC_SL_LDGR_CODE+'/'+PC_SL_ACNO, SUM( DECODE(PC_SL_LDGR_CODE,'02',1,-1) *PC_AMOUNT), PC_CHEQUE_NO CHQNO FROM GLAS_PDC_CHEQUES WHERE PC_RESUB_REF IS NOT NULL AND PC_DISCD NOT IN ('d','D','T') GROUP BY PC_RES...

How to add license functionality in my VB.NET application

Hi, I am using VB.NET for coding and SQL Server 2005 for database. My application is ready for release. Just on thing missing before I can go live. I want to implement license concept in my application. My license file can be text or xml file. In which there should be some encrypted matter which will be used for validate the applicat...

Best method for importing csv or excel file to SQL Server 2005 using .net MVC view

Hi, I'm looking for the best method for importing csv or excel file to SQL Server 2005 using .net MVC. Thank you. ...

SQL Server converting a variable varchar field to money/decimal/something with decimal places

I'm looking for an elegant way to convert a field of type varchar, with variable data in it, to a data type which can be used for mathematical operations sample data from the field (excluding quotes) '' 'abc' '23' '23.2' The method should work for all, and for the first & second values should return 0, and not throw an SQL Server err...

Query Executing Problem

Using SQL 2005: “Taking too much time to execute” I want to filter the date, the date should not display in holidays, and I am using three tables with Inner Join When I run the below query, It taking too much time to execute, because I filter the cardeventdate with three table. Query SELECT PERSONID, CardEventDate tmp_cardevent3 ...

How to notify a windows service(c#) of a DB Table Change(sql 2005)?

I have a table with a heavy load(many inserts/updates/deletes) in a SQL2005 database. I'd like to do some post processing for all these changes in as close to real time as possible(asynchronously so as not to lock the table in any way). I've looked a number of possible solutions but just can't seem to find that one neat solution that fee...

use column alias in other calculation in sql server 2005

I am working with the following query.I want to use Date_Sent_to_Recorder in my other calculations which follows.I am getting an error "Invalid column name 'Date_Sent_to_Recorder'." People recommended using a CTE for this but i am not able to fit it in this scenerio.I have a correlated subquery which calculates Date_Sent_to_Recorder.Plea...

SQL Server blocking on 'create function...', what does this imply?

Hi folks, I've used the sql from this article http://blogs.techrepublic.com.com/datacenter/?p=275 to try and track down the cause of a lot of blocking which has been going on recently within my sql server 2005 database. A number of times, all the processes returned are calling 'create function...', the functions vary but a number of the...

SQL Server Templates - How Do I Escape The Less Than Character?

I like to use SQL Server 2005 templates to run frequently used queries. You can include parameters in your templates using this syntax: <LastName, varchar, 'Bob'> I have a query that needs the less than or equals to operator <= but unfortunately the SQL Server 2005 template interprets that as the start of a parameter. I have been unab...

How can I display two rows worth of data on one line side-by-side in Report Designer?

I am using SQL Server Reporting Services 2005, and I'm developing a report in Report Designer/Business Intelligence Studio. Right now I have a normal-looking table that displays data like this: ---------------- | A | B | C | ---------------- | A1 | B1 | C1 | ---------------- | A2 | B2 | C2 | ---------------- | A3 | B3 | C3 | --------...

How to Calculate Median?

I need to calculate a median on a set of data, so I created a temp table and have tried to follow some articles online with zero success, here is what I am working with: CREATE TABLE #QuizTemp (QuizProfileID INT,Cnt INT,TotalScore INT) INSERT INTO #QuizTemp SELECT QuizAnswers.QuizProfileID, COUNT(QuizAnswers.QuizProfileID) AS Cnt, SUM(...

MDX geographic distance calculation

I'm using SQL Server 2005 Analysis Services and I'm trying to calculate distance inside of an MDX query - so that I can get counts of the items that are near my current location. I've created a dimension with Latitude & Longitude, and have also created a .NET assembly to do the math - but am having a hard time getting it all to work out...

how not to hard code connection stringin all pages

I have a webconfig file which has a connectionstring in it... But then when ever i access a database i have to write the same connectionstring again and again... is there a way it can take the value of the connectionstring from the webconfig file itself..???? System.Data.SqlClient.SqlConnection dataConnection = new SqlConnection(); ...

(SQL) Grouping by End of week

I have a report which needs to total up the number of registrations per week, over the last ten weeks and display it as "Week Ending October 10th, 2009" 500" "Week Ending OCtober 3rd, 2009" 400" "Week Ending September 26, 2009" 1000" etc... Here is my query: SELECT Count(*) as [Total] ,Week = DateAdd(day, -1 * da...

DateTime in SSAS

I have a DateTime column in my Time dimension table. I want to display this as just MM/DD/YYYY and hide the time component (which is 00:00:00 anyways). How do I do this? ...

Get the date of a given day in a given week...

i need to start at a year-month and work out what the date it is in a given week, on a given day within that week.. i.e year: 2009 month: 10 week: 5 day-number: 0 would return 2009-10-25 00:00:00 which is a sunday. Notice week 5, there is no day 0 in week 5 in 2009-10 as the sunday in that logical week is 2009-11-01 00:00:00... so w...

How to fix "domain error" in SQL Server 2005 when using LOG() function to get product of set

I have a inline select statement to calculate the product of the set of values. Since SQL Server 2005 doesn't have a built in Product aggregate function, I am using LOG/EXP to get it. My select statement is: (select exp(sum(log(value))) from table where value > 0) Unfortunately I keep getting the following error: Msg 3623, Level 16...

Foreign Key constraint

Hi Two table are tied with each other because of FK constraint. I am trying to update these tables by disabling ALL Trigger but still getting the following error :- The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_TEST_REFERRING_REFPHYSI". The conflict occurred in database "ccdb", table "dbo.RefPhysician", column 'R...

How to replace attribute value of *all* matching elements with XQuery?

Hi, I'm trying without luck to create a modify() statement to change the value of an attribute in all elements that have that attribute value -- so far I can only get it to change the value in the first matched element. I created an example below of what I have so far, which I'm running in SQL Server 2005: DECLARE @x XML SELECT @x = ' ...

What is causing "Subquery returned more than 1 value..." error?

Hi I dont have any idea why am i getting this error :- Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated. I was trying to run this query:- ALTER TABLE Test1 NOCHECK CONSTRAINT ALL ALTER TABLE Test2 ...