Showing posts with label written. Show all posts
Showing posts with label written. Show all posts

Tuesday, March 27, 2012

Converting Crystal Report formula to SSRS

Converting Crystal Report formula to SSRS

I've got a formula written in Crystal Reports that I'm trying to re-do in SSRS 2005. I've just been using Crystal Reports for so long, I've got a mental road-block today.

Here is the formula in Crystal Reports:
IF {V_VIEW.FIELD1} IN ["AAA", "BBB", "CCC", "DDD",
"EEE", "FFF"]
THEN ({V_VIEW.FIELD2}&"*")
ELSE ({V_VIEW.FIELD2})

(It concatonates an asterisk to the end of FIELD2 if FIELD1 contains on of the values in the list.)

In SSRS I'd like to cause an entire row to be bold if FIELD1 contains one of the values in the list.

So in SSRS I'm putting an expression into the FontWeight properties of the TableRow and trying for something (which doesn't work yet) like:
=iif (Fields!FIELD1.Value IN ("AAA", "BBB", "CCC", "DDD", "EEE", "FFF"), "BOLD", "NORMAL")

(SSRS doesn't like the "IN" in the above statement.)

Can anyone offer a suggestion on how to write this for SSRS?

Thanks!
-ErikR

UPDATE

2007-SEPT-17

Ok. I found a workable solution. Does anyone have a better suggestion than the following? The below works but it seems it could be done more simply... Any suggestions?

=iif (Fields!FIELD1.Value = "AAA","Bold",
iif(Fields!FIELD1.Value = "BBB","Bold",
iif(Fields!FIELD1.Value = "CCC","Bold",
iif(Fields!FIELD1.Value = "DDD","Bold",
iif(Fields!FIELD1.Value = "EEE","Bold",
iif(Fields!FIELD1.Value = "FFF","Bold",
iif(Fields!FIELD1.Value = "GGG","Bold",
iif(Fields!FIELD1.Value = "HHH","Bold",
iif(Fields!FIELD1.Value = "III","Bold",
iif(Fields!FIELD1.Value = "JJJ","Bold",
iif(Fields!FIELD1.Value = "KKK","Bold",
iif(Fields!FIELD1.Value = "LLL","Bold",
iif(Fields!FIELD1.Value = "MMM","Bold",
iif(Fields!FIELD1.Value = "NNN","Bold",
iif(Fields!FIELD1.Value = "OOO","Bold",
iif(Fields!FIELD1.Value = "PPP","Bold",
"Normal"))))))))))))))))

Take a look at the VB.NET Switch function for more concise syntax. Alternatively, you can code a custom function that parses the field value any way you want.

Sunday, March 25, 2012

converting binary data to another data type

I have a client application written in C++ to takes an array of doubles and
stores it into a SQL Server 2000 database as an image data type.
We just upgraded to Visual Studio 2005 and SQL Server 2005.
Can the Reporting Services take this image data and convert it to an array
of doubles so that it can be displayed using Reporting Services?
Thanks,
GloriaGloria (Gloria@.discussions.microsoft.com) writes:
> I have a client application written in C++ to takes an array of doubles
> and stores it into a SQL Server 2000 database as an image data type.
> We just upgraded to Visual Studio 2005 and SQL Server 2005.
> Can the Reporting Services take this image data and convert it to an array
> of doubles so that it can be displayed using Reporting Services?
I don't know Reporting Services, so I canot answer the question with any
certainty, but my gut feeling is that you would have to call some piece
of code to unpack that array. Tip: there is a Reporting Services newsgroup,
microsoft.public.sqlserver.reportingsvcs.
The main reason I post, is that I can't refrain from making the comment
table design appears a bit unorthodox to me. Or to put it more bluntly, a
serious violation of first normal form since it includs a repearing
group. The normal way of storing the data would be have a subtable,
and store one float value on each row.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Sunday, March 11, 2012

convert subqueries to join

Hi all,
Recently saw some posts about how bad it is using subqueries (nested queries) and things like all the queries can be written with JOIN instead. However, for a query like the followings, I cannot figure out how to do it properly.

The data looks like the following, it contains 3 columns, id, which is the primary key of the table (unique), group, as which group this entry belongs to, and the article type, where 0 is not an article.

id grp article
1 1 0
2 1 0
3 1 0
4 1 3
5 1 2
6 1 0
7 2 0
8 2 3
9 2 1
10 2 0
11 2 0
12 2 0
13 3 5
14 3 2
15 3 0
16 3 0
17 3 1
18 3 1

What the query is trying to achieve is for each group, get the latest (maximum) id, and the article type (bear in mind "0" is not one of the allowed type). so for data above, the result will look something like this...

id grp article
5 1 2
9 2 1
18 3 1

The following is the query I come up with, the problem is, I don't know how to get the same result without using subquery. I don't even see how it is possible. Guys, please share some light with me, and educate me on this.

select a.id, a.grp, b.article
from
(
SELECT max(id) as id, grp
from list a
where article != 0
group by grp
) a
join list b
on a.id = b.id

thanks in advance!!!

Here it is,

Code Snippet

Create Table #data (

[id] int ,

[grp] int ,

[article] int

);

Insert Into #data Values('1','1','0');

Insert Into #data Values('2','1','0');

Insert Into #data Values('3','1','0');

Insert Into #data Values('4','1','3');

Insert Into #data Values('5','1','2');

Insert Into #data Values('6','1','0');

Insert Into #data Values('7','2','0');

Insert Into #data Values('8','2','3');

Insert Into #data Values('9','2','1');

Insert Into #data Values('10','2','0');

Insert Into #data Values('11','2','0');

Insert Into #data Values('12','2','0');

Insert Into #data Values('13','3','5');

Insert Into #data Values('14','3','2');

Insert Into #data Values('15','3','0');

Insert Into #data Values('16','3','0');

Insert Into #data Values('17','3','1');

Insert Into #data Values('18','3','1');

Code Snippet

Select data.* from #data data

inner join (Select Max(id) id, grp from #data group By grp) maxid

on maxid.id=data.id

On SQL Server 2005,

Code Snippet

;With CTE

as

(

Select data.*,Max(id) Over(partition by grp) maxid from #data data

)

Select id,grp,article from cte where id=maxid

|||Hi Manivannan,

thank you for the quick reply, one problem that I saw was you didn't check that article cannot be 0, but anyway, it doesn't matter.

I got a few questions tho. the first query that you posted is actually very similiar to the one I posted. You still use a nested query. the inter query identifies the max id of the entries grouped by the grp, then, join to the tabe (#data) to get the article#. The only difference I saw was that you put the inner query after the join statement. so instead of select * from a join b on a.id = b.id, you did something like select * from b join a on a.id = b.id

the second query, which is MSSQL 2005 specific, which to me, is still using a nested query. In there, you first specify CTE, then you do a select statement on top of it, which still look like a nested query to me.

Is it possible to use a straightforward query to achieve what I wanted to achieve? i.e. do just normal join with data, etc. because i reallly don't see how it can be done.

thanks so much about the answer tho, appreciated!
|||

Hi Ken,

For your requirement we have to use the subquery. Without subquery we can't achive this result.

In SQL server 2005, CTE is best option to use..

-Mani

|||

Do not get confused with "derived table" and "correlated subquery". Try to avoid the second one, if possible. Always test before deciding for the final approach.

The first one, the one you are using in your post, is executed once. The second one seems to be executed for every row in the outer reference, but it is better to verify the execution plan.

Examples:

select a.*

from list as a

where a.[id] = (select max([b.id]) from list as b where b.grp = a.grp)

go

select a.*

from list as a

where not exists (

select *

from list as b

where b.grp = a.grp and b.[id] > a.[id]

)

go

AMB

|||so, is

select a.*

from list as a

where a.[id] = (select max([b.id]) from list as b where b.grp = a.grp)

a correlated subquery?
because it looks to me for every row retrieved from list, this "(select max([b.id]) from list as b where b.grp = a.grp)" statement will be executed.

So I should execute the query the way I did (for SQL2000) and use CTE for SQL 2005? by the way, I tried the query in SQL 2005, and the execution time is reduced quite a lot. What made it so different to the subqueries I have?

somehow, the text looks different in the edit mode and browse mode >"<

|||

Can you change the font of your post, please?

I can not read it at all.

Thanks,

AMB

Wednesday, March 7, 2012

Convert RS2005 rdl to RS2000

Hi,

Is there any tool that can convert a report definition language file written for RS2005 to be compatible with RS2000?

Any help will be appreciated.

Thank you.

Peter

Microsoft does not provide a RDL-downgrade tool. Not sure if anyone else has built one and made it available to the public. Anyway, it would not be difficult to build a tool yourself, or just follow the manual steps described in this thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=414302&SiteID=1

The manual steps cover almost 100% of RDLs (I omitted custom report item and custom properties).

-- Robert

Friday, February 10, 2012

convert data file type from unix to pc using stored procedure?

Hi, I have a script written in ASP to load data file (.csv) to ms sql. In the script, I have a portion of script looks like taht :

....

Do While NOT oInFile.AtEndOfStream
oOutFile.WriteLine Replace(oInFile.Readline, chr(13), vbcrlf)
Loop

....

After that, I will use a BULK INSERT to input data to ms sql.

I am wondering how do I convert each row (data) to vbcrlf in Stored Procedure? Coz' I did not compose the convertion part, and I got no error when running BULK INSERT, but no rows are inserted :( HELP!!!!

I guess it's because the file is not being converted into a correct format??

Can you give more information? e.g.: sample text used in BULK INSERT, BULK INSERT command you're using, and the schema of the destination table.