Showing posts with label expression. Show all posts
Showing posts with label expression. Show all posts

Friday, March 30, 2012

How to Create Rank column

If I have a column like this

value

34
45
54

How can I write an expression to create corresponding Rank column.

value Rank
--
34 3
45 2
54 1
Thanks
well, Lest this thread should remain hanged...I have solved this at the stored procedure level. I did not find any means by which I could do it in the reporting server.

Thanks
Ragz.|||Why couldn't you sort the column by value and use the RowCount() function?|||I have the same problem.
I have many Cognos Reports to be converted in Reporting Services.
Out of which there are several Ranking Reports.
Cognos has inbuilt Rank Function while SSRS does not have.
I dont want to do grouping on Database level, rather trying to find a solution in RS.
But unfortunately I couldnt find any solution.
I sorted the group according to requirement, now only thing left is showing the rank number and limiting top 60 rows only.
I tried filters to show TopN, but always gives and error and also tried custom code to show the row number for that group but didn't work.

Anyone has any idea how to overcome this limitation of Reporting Services.
One more interesting is when I try to create a field in dataset having IIF and / within.. RS terminates, all unsaved work gone.
Sometimes I think Microsoft cannot have a product which is 100% perfact and working. Smile

|||

If you are using SQL Server 2005 and creating based on a query you can certainly use the row_number() function; something like

Code Snippet

select value,

row_number() over

( order by value

) as rank

from yourTable

|||I wanted to implement the Rank function in Reporting Services but I couldn't,
so the only solution left is at database level, so I grouped everything in PL-SQL query itself.
I also used Partition by clause in Rank function as per the report requirement.

Anyway thank you guys for your help, I hope microsoft would add more features in its upcoming 2008 products.

Nik|||

The rowcount() feature in RS as suggested above might be able to solve this, as well as the Top N issue. I currently use it to shade every other row by combining it with Mod.

|||rowcount() and TopN in RS are for simple reports, I have very complex reports and the rank() function in PL/SQL is working perfact for me.
And as I said RS (visual studio) terminates when you add a new formula column in a dataset which has sum and '/' within IIF expression.

How to Create Rank column

If I have a column like this

value

34
45
54

How can I write an expression to create corresponding Rank column.

value Rank
--
34 3
45 2
54 1
Thanks
well, Lest this thread should remain hanged...I have solved this at the stored procedure level. I did not find any means by which I could do it in the reporting server.

Thanks
Ragz.|||Why couldn't you sort the column by value and use the RowCount() function?|||I have the same problem.
I have many Cognos Reports to be converted in Reporting Services.
Out of which there are several Ranking Reports.
Cognos has inbuilt Rank Function while SSRS does not have.
I dont want to do grouping on Database level, rather trying to find a solution in RS.
But unfortunately I couldnt find any solution.
I sorted the group according to requirement, now only thing left is showing the rank number and limiting top 60 rows only.
I tried filters to show TopN, but always gives and error and also tried custom code to show the row number for that group but didn't work.

Anyone has any idea how to overcome this limitation of Reporting Services.
One more interesting is when I try to create a field in dataset having IIF and / within.. RS terminates, all unsaved work gone.
Sometimes I think Microsoft cannot have a product which is 100% perfact and working. Smile

|||

If you are using SQL Server 2005 and creating based on a query you can certainly use the row_number() function; something like

Code Snippet

select value,

row_number() over

( order by value

) as rank

from yourTable

|||I wanted to implement the Rank function in Reporting Services but I couldn't,
so the only solution left is at database level, so I grouped everything in PL-SQL query itself.
I also used Partition by clause in Rank function as per the report requirement.

Anyway thank you guys for your help, I hope microsoft would add more features in its upcoming 2008 products.

Nik|||

The rowcount() feature in RS as suggested above might be able to solve this, as well as the Top N issue. I currently use it to shade every other row by combining it with Mod.

|||rowcount() and TopN in RS are for simple reports, I have very complex reports and the rank() function in PL/SQL is working perfact for me.
And as I said RS (visual studio) terminates when you add a new formula column in a dataset which has sum and '/' within IIF expression.
sql

How to Create Rank column

If I have a column like this

value

34
45
54

How can I write an expression to create corresponding Rank column.

value Rank
--
34 3
45 2
54 1
Thankswell, Lest this thread should remain hanged...I have solved this at the stored procedure level. I did not find any means by which I could do it in the reporting server.

Thanks
Ragz.|||Why couldn't you sort the column by value and use the RowCount() function?|||I have the same problem.
I have many Cognos Reports to be converted in Reporting Services.
Out of which there are several Ranking Reports.
Cognos has inbuilt Rank Function while SSRS does not have.
I dont want to do grouping on Database level, rather trying to find a solution in RS.
But unfortunately I couldnt find any solution.
I sorted the group according to requirement, now only thing left is showing the rank number and limiting top 60 rows only.
I tried filters to show TopN, but always gives and error and also tried custom code to show the row number for that group but didn't work.

Anyone has any idea how to overcome this limitation of Reporting Services.
One more interesting is when I try to create a field in dataset having IIF and / within.. RS terminates, all unsaved work gone.
Sometimes I think Microsoft cannot have a product which is 100% perfact and working. Smile|||

If you are using SQL Server 2005 and creating based on a query you can certainly use the row_number() function; something like

Code Snippet

select value,

row_number() over

( order by value

) as rank

from yourTable

|||I wanted to implement the Rank function in Reporting Services but I couldn't,
so the only solution left is at database level, so I grouped everything in PL-SQL query itself.
I also used Partition by clause in Rank function as per the report requirement.

Anyway thank you guys for your help, I hope microsoft would add more features in its upcoming 2008 products.

Nik|||

The rowcount() feature in RS as suggested above might be able to solve this, as well as the Top N issue. I currently use it to shade every other row by combining it with Mod.

|||rowcount() and TopN in RS are for simple reports, I have very complex reports and the rank() function in PL/SQL is working perfact for me.
And as I said RS (visual studio) terminates when you add a new formula column in a dataset which has sum and '/' within IIF expression.

Wednesday, March 28, 2012

How to Create Rank column

If I have a column like this

value

34
45
54

How can I write an expression to create corresponding Rank column.

value Rank
--
34 3
45 2
54 1
Thanks
well, Lest this thread should remain hanged...I have solved this at the stored procedure level. I did not find any means by which I could do it in the reporting server.

Thanks
Ragz.|||Why couldn't you sort the column by value and use the RowCount() function?|||I have the same problem.
I have many Cognos Reports to be converted in Reporting Services.
Out of which there are several Ranking Reports.
Cognos has inbuilt Rank Function while SSRS does not have.
I dont want to do grouping on Database level, rather trying to find a solution in RS.
But unfortunately I couldnt find any solution.
I sorted the group according to requirement, now only thing left is showing the rank number and limiting top 60 rows only.
I tried filters to show TopN, but always gives and error and also tried custom code to show the row number for that group but didn't work.

Anyone has any idea how to overcome this limitation of Reporting Services.
One more interesting is when I try to create a field in dataset having IIF and / within.. RS terminates, all unsaved work gone.
Sometimes I think Microsoft cannot have a product which is 100% perfact and working. Smile

|||

If you are using SQL Server 2005 and creating based on a query you can certainly use the row_number() function; something like

Code Snippet

select value,

row_number() over

( order by value

) as rank

from yourTable

|||I wanted to implement the Rank function in Reporting Services but I couldn't,
so the only solution left is at database level, so I grouped everything in PL-SQL query itself.
I also used Partition by clause in Rank function as per the report requirement.

Anyway thank you guys for your help, I hope microsoft would add more features in its upcoming 2008 products.

Nik|||

The rowcount() feature in RS as suggested above might be able to solve this, as well as the Top N issue. I currently use it to shade every other row by combining it with Mod.

|||rowcount() and TopN in RS are for simple reports, I have very complex reports and the rank() function in PL/SQL is working perfact for me.
And as I said RS (visual studio) terminates when you add a new formula column in a dataset which has sum and '/' within IIF expression.

How to Create Rank column

If I have a column like this

value

34
45
54

How can I write an expression to create corresponding Rank column.

value Rank
--
34 3
45 2
54 1
Thanks
well, Lest this thread should remain hanged...I have solved this at the stored procedure level. I did not find any means by which I could do it in the reporting server.

Thanks
Ragz.|||Why couldn't you sort the column by value and use the RowCount() function?|||I have the same problem.
I have many Cognos Reports to be converted in Reporting Services.
Out of which there are several Ranking Reports.
Cognos has inbuilt Rank Function while SSRS does not have.
I dont want to do grouping on Database level, rather trying to find a solution in RS.
But unfortunately I couldnt find any solution.
I sorted the group according to requirement, now only thing left is showing the rank number and limiting top 60 rows only.
I tried filters to show TopN, but always gives and error and also tried custom code to show the row number for that group but didn't work.

Anyone has any idea how to overcome this limitation of Reporting Services.
One more interesting is when I try to create a field in dataset having IIF and / within.. RS terminates, all unsaved work gone.
Sometimes I think Microsoft cannot have a product which is 100% perfact and working. Smile

|||

If you are using SQL Server 2005 and creating based on a query you can certainly use the row_number() function; something like

Code Snippet

select value,

row_number() over

( order by value

) as rank

from yourTable

|||I wanted to implement the Rank function in Reporting Services but I couldn't,
so the only solution left is at database level, so I grouped everything in PL-SQL query itself.
I also used Partition by clause in Rank function as per the report requirement.

Anyway thank you guys for your help, I hope microsoft would add more features in its upcoming 2008 products.

Nik|||

The rowcount() feature in RS as suggested above might be able to solve this, as well as the Top N issue. I currently use it to shade every other row by combining it with Mod.

|||rowcount() and TopN in RS are for simple reports, I have very complex reports and the rank() function in PL/SQL is working perfact for me.
And as I said RS (visual studio) terminates when you add a new formula column in a dataset which has sum and '/' within IIF expression.

How to create Parameter Field with embedded SQL

I want to create an expression field on my report that performs an sql statement that I specify to bring back a total instead of using the built-n functions for SSRS, how can I do this? Basically just like in Crystal where you can create a formula field that runs a sql statement then brings back a value from your sql statement. This value is not related to the other data in the report...so yes in theory you may be thinking subreport...is tha the only way? or can I create some sort of textbox that shows the total I want below?

DECLARE @.TotalDaysInMonth int,

@.today datetime,

@.TotalWeekendDays int,

@.TotalHolidaysThisMonth int,

@.TotalPostingDays int

SET @.today = GETDATE()

-- TOTAL DAYS THIS MONTH

SET @.TotalDaysInMonth = CASE WHEN DatePart(mm,GetDate()) IN (1,3,5,7,8,10,12) THEN

31

ELSE

DateDiff(day,GetDate(),DateAdd(mm, 1, GetDate()))

END

SELECT @.TotalDaysInMonth

-- TOTAL HOLIDAYS THIS MONTH

SELECT @.TotalHolidaysThisMonth = (SELECT COUNT(*) FROM Apex_ReportingServer.dbo.Holidays

WHERE HolidayDate BETWEEN (DATEADD(DAY, -DATEPART(DAY, @.today) + 1, @.today))

AND (DATEADD(DAY, -DATEPART(DAY, @.today), DATEADD(MONTH, 1, @.today))))

SELECT @.TotalHolidaysThisMonth

-- TOTAL # WEEKEND DAYS THIS MONTH

DECLARE @.date DATETIME

SET @.date = '20060101'

SELECT @.TotalWeekendDays = 8 +

CASE WHEN ISDATE(CONVERT(CHAR(6), @.date, 112) + '29') = 1 THEN

CASE WHEN DATENAME(WEEKDAY, CONVERT(CHAR(6), @.date, 112) + '01') IN ('Saturday', 'Sunday')

THEN 1 ELSE 0 END ELSE 0 END +

CASE WHEN ISDATE(CONVERT(CHAR(6), @.date, 112) + '30') = 1 THEN

CASE WHEN DATENAME(WEEKDAY, CONVERT(CHAR(6), @.date, 112) + '02') IN ('Saturday', 'Sunday')

THEN 1 ELSE 0 END ELSE 0 END +

CASE WHEN ISDATE(CONVERT(CHAR(6), @.date, 112) + '31') = 1 THEN

CASE WHEN DATENAME(WEEKDAY, CONVERT(CHAR(6), @.date, 112) + '03') IN ('Saturday', 'Sunday')

THEN 1 ELSE 0 END ELSE 0 END

SELECT @.TotalWeekendDays

SELECT @.TotalPostingDays = @.TotalDaysInMonth - (@.TotalHolidaysThisMonth + @.TotalWeekendDays)

SELECT @.TotalPostingDays

You could simply add the SQL Statement above to a new/different Dataset and reference that Dataset in the given field on your report...does that make sense, or am I missing something?

|||exactly thanks! I actually tried that and it worked before you posted...thanks you were right on.

How to create Parameter Field with embedded SQL

I want to create an expression field on my report that performs an sql statement that I specify to bring back a total instead of using the built-n functions for SSRS, how can I do this? Basically just like in Crystal where you can create a formula field that runs a sql statement then brings back a value from your sql statement. This value is not related to the other data in the report...so yes in theory you may be thinking subreport...is tha the only way? or can I create some sort of textbox that shows the total I want below?

DECLARE @.TotalDaysInMonth int,

@.today datetime,

@.TotalWeekendDays int,

@.TotalHolidaysThisMonth int,

@.TotalPostingDays int

SET @.today = GETDATE()

-- TOTAL DAYS THIS MONTH

SET @.TotalDaysInMonth = CASE WHEN DatePart(mm,GetDate()) IN (1,3,5,7,8,10,12) THEN

31

ELSE

DateDiff(day,GetDate(),DateAdd(mm, 1, GetDate()))

END

SELECT @.TotalDaysInMonth

-- TOTAL HOLIDAYS THIS MONTH

SELECT @.TotalHolidaysThisMonth = (SELECT COUNT(*) FROM Apex_ReportingServer.dbo.Holidays

WHERE HolidayDate BETWEEN (DATEADD(DAY, -DATEPART(DAY, @.today) + 1, @.today))

AND (DATEADD(DAY, -DATEPART(DAY, @.today), DATEADD(MONTH, 1, @.today))))

SELECT @.TotalHolidaysThisMonth

-- TOTAL # WEEKEND DAYS THIS MONTH

DECLARE @.date DATETIME

SET @.date = '20060101'

SELECT @.TotalWeekendDays = 8 +

CASE WHEN ISDATE(CONVERT(CHAR(6), @.date, 112) + '29') = 1 THEN

CASE WHEN DATENAME(WEEKDAY, CONVERT(CHAR(6), @.date, 112) + '01') IN ('Saturday', 'Sunday')

THEN 1 ELSE 0 END ELSE 0 END +

CASE WHEN ISDATE(CONVERT(CHAR(6), @.date, 112) + '30') = 1 THEN

CASE WHEN DATENAME(WEEKDAY, CONVERT(CHAR(6), @.date, 112) + '02') IN ('Saturday', 'Sunday')

THEN 1 ELSE 0 END ELSE 0 END +

CASE WHEN ISDATE(CONVERT(CHAR(6), @.date, 112) + '31') = 1 THEN

CASE WHEN DATENAME(WEEKDAY, CONVERT(CHAR(6), @.date, 112) + '03') IN ('Saturday', 'Sunday')

THEN 1 ELSE 0 END ELSE 0 END

SELECT @.TotalWeekendDays

SELECT @.TotalPostingDays = @.TotalDaysInMonth - (@.TotalHolidaysThisMonth + @.TotalWeekendDays)

SELECT @.TotalPostingDays

You could simply add the SQL Statement above to a new/different Dataset and reference that Dataset in the given field on your report...does that make sense, or am I missing something?

|||exactly thanks! I actually tried that and it worked before you posted...thanks you were right on.sql

Monday, March 26, 2012

how to create function which eval expression

hi all,
I would like to create a function which can eval string expressiion
select dbo.fn_eval_string('1+2+3')
return 6
and if I do dbo.fn_eval_string('2-(5-3)')
return 0
is that possible? it should also support multiply and division.Kevin,
One possible solution is to use dynamic sql, but you can not use it in a
udf. You will have to use a stored procedure instead.
Example:
create procedure p1
@.s varchar(50),
@.i int output
as
set nocount on
declare @.sql varchar(4000)
set @.sql = N'select @.i = ' + @.s
exec sp_executesql @.sql, N'@.i int output', @.i output
go
declare @.i int
exec p1 '2 * (3 + 5)', @.i output
print @.i
go
The code has not been tested.
Be careful with the use of dynamic sql, there are pros and cons that you
should be aware of, before using it.
http://www.sommarskog.se/dynamic_sql.html
AMB
"Kevin" wrote:

> hi all,
> I would like to create a function which can eval string expressiion
> select dbo.fn_eval_string('1+2+3')
> return 6
> and if I do dbo.fn_eval_string('2-(5-3)')
> return 0
> is that possible? it should also support multiply and division.
>
>