Tag: sql-server

How to get all SSRS Subscription Data using stored procedure?

I am new to ssrs. I want to get all the possible data for ssrs subscribed report, which are Available in ResportServer database. I have found some queries, but that does not have proper data. It only works for single report. I need list of unique subscription with it’s data. If possible stored procedure is […]

SQL:How can I find unique date ranges from a given a set of date ranges?

I have a table of users along with their date ranges in INT format(yyyymmdd) as below: Id Name StartDate EndDate 1 abc 20160216 20160217 1 abc 20160228 20160228 1 abc 20160301 20160301 1 abc 20160301 20160302 1 abc 20160301 20170401 1 abc 20160302 20160302 1 abc 20160303 20160303 1 abc 20160303 20170401 3 def 20160217 […]

Sql Update Count Details after grouping

I have multiple tables in my SQL Server database. I have one table say Table A which has fields like dispatch,filename,etc. The second table say Table B has filedetails like filename, dispatchcount, totalcount etc. There are many other fields in both tables but not relevant to this question. Requirement is : I want to update […]

C# “System.IndexOutOfRangeException: There is no row at position 0” when using Stored Procedure

I have a very strange issue : I am taking data out of the SQL using a Stored Procedure : ‘CREATE PROCEDURE [dbo].[GET_RECMP_BY_PH_Code] @PH_Code NVARCHAR(50) AS SELECT Recurrent_PH_MP.Phase_Code AS Phase_Code, MP_BGT.FY_Code AS Fiscal_Year, MP_BGT.Budget_Type AS Budget_Type, MP_BGT.Currency_Symbol AS Currency, ISNULL(dbo.Get_RECEH_Days_BY_PHCode_FYCode(@PH_Code, MP_BGT.FY_Code, MP_BGT.Currency_Symbol, MP_BGT.Budget_Type), 0) AS EH_Days, ISNULL(dbo.Get_RECNH_Days_BY_PHCode_FYCode(@PH_Code, MP_BGT.FY_Code, MP_BGT.Currency_Symbol, MP_BGT.Budget_Type), 0) AS NH_Days, ISNULL(ROUND(dbo.Get_RECEH_Val_BY_PHCode_FYCode(@PH_Code, MP_BGT.FY_Code, […]

Selecting and deleting duplicated rows for particular columns SQL

I have an sql table that saves Locations, ID Name X Y Z ————————- 1 Loc1 12 24 45 2 Loc2 12 24 60 3 Loc3 54 32 33 4 Loc4 54 32 64 5 Loc5 98 66 90 6 Loc6 98 66 77 7 Loc7 44 50 98 Some Location coordinates (x and y) […]

Can i use Pivot for this?

I have a table with the data below. ID | NAME | DPT | Country | School | Course ——————————————————————- 8888 | John | ABC | Japan | ABC Uni | English 8888 | John | ABC | Japan | ABC Uni | Engineering 8888 | John | ABC | England | EFG Uni | […]

Hiding a row where value = 0 but count its other column values in total calculations – sql2008

I have tables like that: (C1-C2 varchar(10), C3-Number int) WaitingData C1 C2 C3 Number A B 1 10 A B 2 0 A B 3 4 X B 4 2 CompletedData C1 C2 C3 Number A B 1 5 A B 2 2 A B 3 0 X B 4 12 I am using the […]

Generate Date Range and Apply calculation on each Record SQL

I have the following case (excel format): Date Start: 2016-01-01 Date Finish: 2016-12-31 Max Value: 96 Point Value: 0.0972 So If I change those parameter above, the record will change. For instance result below: Date Value —————————– 2016-01-01 96 –> This value is taken from MaxValue Parameter 2016-01-02 95.9 –> It requires a formula, which […]

What does the value -9 means for fetch_status in SQL Server?

I am trying to get the fetch_status for each cursor in a nested loop. I am unable to use @@FETCH_STATUS here because of the nested loops (loop within another loop) My first approach is to use [sys.dm_exec_cursors][1] to determine the status of each cursor by a name. Then if the fetch_status is not equal to […]

Why do I have different result by using CASE statement?

I am using CASE statement to calculate Premium and result is way off if I just use SELECT SUM statement. Why would that be? select SUM(CASE WHEN Premium > 0 and Premium <= 5000 AND Year(EffectiveDate)=2016 AND PolicyType = ‘New Business’ THEN Premium ELSE 0 END) as ‘0-5K_WP’, SUM(CASE WHEN Premium > 5000 and Premium […]

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