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

Thursday, March 8, 2012

Can Image Size be an expression? How?

Hello,
I need to set image size on my report with expression. Is it possible? If
yes, how?
Your regards,No
Even Chart size is also not expressionable

Saturday, February 25, 2012

Can I use CASE expression in AND condition?

Hello:
Is it possible to useCASE expression inAND condition? i.e.
-------------
CREATE PROC spBlah
(
@.id INT,
@.val INT
)
AS
SELECT *
FROM aTable
WHERE tableID = @.id
AND
(
CASE @.val WHEN 1 THEN otherCol = someValue END
CASE @.val WHEN 2 THEN otherCol != someOtherVlaue END
)
--------------AND is a Boolean Operator and is also a JOIN condition operator used by databases like SQL Server for extra JOIN search conditions. I don't think it can be used with a CASE statement. Try the link below for CASE statement code. Hope this helps.
http://www.craigsmullins.com/ssu_0899.htm|||For your case, you might try to build the query dynamically and store the query into a SQL variable. Then use the exec method to execute the query. I don't think you can do the way you are heading. Build only the variable part and then append to the fixed part. Hope I am not confusing you...
declare @.tmp varchar(300)
if(@.val = 1)
set @.tmp = 'otherCol = someValue'
else
set @.tmp = 'otherCol != someOtherVlaue'
set @.tmp = 'SELECT * FROM aTable WHERE tableID = @.id AND ' + @.tmp
exec(@.tmp)
Thanks

Friday, February 24, 2012

Can I update several columns with CASE expressions using SQL at the same time?

Hi, all here,

I am having a question about update several columns with CASE expression in SQL Server 2005 database engine. Is it possible to do that in SQL Server 2005 database engine?

Thanks a lot in advance for any help and guidance.

Can you be more specific about what you're trying to achieve? Using CASE in an update statement is perfectly legal. For instance you can set the value of a column based on a case statement:

declare @.var int

set @.var = 10

update T1 set Col1 = case @.var when 1 then 'Something' when 2 then 'Something2' else 'SomethingElse' end

where Col1 = 1

Can I update several columns by CASE expressions?

Hi, all here,

I am having a question-is it possible to update several columns using CASE expression in SQL language? like if I wanna set each CASE for each column.

Thanks a lot in advance for any help and guidance.

I think so. Have you tried something and it didn't work? A CASE expression just returns a scalar value, so you can do:

update tablename
set column1 = case when .... end,
column2 = case when ... end,

If you want. If the case statements are completely independent of one another this might be the best way to do something, but if they are from the same data set then you might want to use a join, and possibly a derived table.

Post an example and someone will give you an idea

|||Yes, you can.
Few times, i had to create Stored Procedures that work on just one table and all fields did not allow "NULL" values.
E.g.)

CREATE TABLE NewsTitle (
newstitle_id INT IDENTITY PRIMARY KEY
, title NVARCHAR(512)
, page SMALLINT NOT NULL
, media SMALLINT NOT NULL
)

If you would like to create a simple Sproc that will update a record in that table you might do something like(using CASE) the following:

CREATE PROCEDURE UpdateNewsTitle
@.id INT
, @.title NVARCHAR(512)
, @.page SMALLINT
, @.media SMALLINT
AS
BEGIN
UPDATE NewsTitle
SET title = CASE WHEN @.title IS NULL THEN title ELSE @.title END
, page = CASE WHEN @.page IS NULL THEN page ELSE @.page END
, media = CASE WHEN @.media IS NULL THEN media ELSE @.media END
WHERE newstitle_id = @.id
END
GO

But if you are just checking if passed argument is NULL or not and, if argument is not null then try to use that value, you can use COALESCE function to rid of CASE statement like the following:

ALTER PROCEDURE UpdateNewsTitle
@.id INT
, @.title NVARCHAR(512)
, @.page SMALLINT
, @.media SMALLINT
AS
BEGIN
UPDATE NewsTitle
SET title = COALESCE(@.title, title)
, page = COALESCE(@.page, page)
, media = COALESCE(@.media, media)
WHERE newstitle_id = @.id
END
GO

If you are not familiar with COALESCE, you can look it up on BOL(Books Online). In short, COALESCE returns FIRST non-null value.

Sunday, February 19, 2012

Can I sort on fields by in paramters

I need to sort a report in 3 ways 2 fields and one expression.
When i add a field to a parameter it says the following:
"Fields cannot be used in report parameter expressions"
The expression I need to sort on is this
=(sum(Fields!p1beløb.Value) - sum(Fields!p2beløb.Value)) /
(0.001+sum(Fields!p1beløb.Value))
It works if I use this as sort on the group item, but I need to choose
between 3 kinds.
How can I sort the report if I can't use fields to tell how I want it
sorted
?
Jack
--
Jeg beskyttes af den gratis SPAMfighter til privatbrugere.
Den har indtil videre sparet mig for at få 45071 spam-mails.
Betalende brugere får ikke denne besked i deres e-mails.
Hent gratis SPAMfighter her: www.spamfighter.dkCreate a function in the code area which accepts the Parameter ( 1,2 or 3 )
and all of the fields you wish to sort on..
The function should use the parameter in a case/switch statement to choose
which value to return. In one case it should return the value of the
expression you mentioned.
In the sort column pu
=Code.GetSort(Parameters!SortVal.Value,......)
Hope this helps...
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Jack Nielsen" <no_spam jack.nielsen@.get2net.dk> wrote in message
news:ebEGvm9tFHA.1472@.TK2MSFTNGP15.phx.gbl...
>I need to sort a report in 3 ways 2 fields and one expression.
> When i add a field to a parameter it says the following:
> "Fields cannot be used in report parameter expressions"
> The expression I need to sort on is this
> =(sum(Fields!p1beløb.Value) - sum(Fields!p2beløb.Value)) /
> (0.001+sum(Fields!p1beløb.Value))
> It works if I use this as sort on the group item, but I need to choose
> between 3 kinds.
> How can I sort the report if I can't use fields to tell how I want it
> sorted
> ?
> Jack
>
>
> --
> Jeg beskyttes af den gratis SPAMfighter til privatbrugere.
> Den har indtil videre sparet mig for at få 45071 spam-mails.
> Betalende brugere får ikke denne besked i deres e-mails.
> Hent gratis SPAMfighter her: www.spamfighter.dk
>|||I think this is somehow difficult, doesn't other designers need to sort the
result differently based upon fields ?
Jack
"Wayne Snyder" <wayne.nospam.snyder@.mariner-usa.com> skrev i en meddelelse
news:eZbuG$DuFHA.3740@.TK2MSFTNGP14.phx.gbl...
> Create a function in the code area which accepts the Parameter ( 1,2 or
3 )
> and all of the fields you wish to sort on..
> The function should use the parameter in a case/switch statement to choose
> which value to return. In one case it should return the value of the
> expression you mentioned.
> In the sort column pu
> =Code.GetSort(Parameters!SortVal.Value,......)
> Hope this helps...
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Jack Nielsen" <no_spam jack.nielsen@.get2net.dk> wrote in message
> news:ebEGvm9tFHA.1472@.TK2MSFTNGP15.phx.gbl...
> >I need to sort a report in 3 ways 2 fields and one expression.
> >
> > When i add a field to a parameter it says the following:
> >
> > "Fields cannot be used in report parameter expressions"
> >
> > The expression I need to sort on is this
> > =(sum(Fields!p1beløb.Value) - sum(Fields!p2beløb.Value)) /
> > (0.001+sum(Fields!p1beløb.Value))
> >
> > It works if I use this as sort on the group item, but I need to choose
> > between 3 kinds.
> >
> > How can I sort the report if I can't use fields to tell how I want it
> > sorted
> > ?
> >
> > Jack
> >
> >
> >
> >
> > --
> > Jeg beskyttes af den gratis SPAMfighter til privatbrugere.
> > Den har indtil videre sparet mig for at få 45071 spam-mails.
> > Betalende brugere får ikke denne besked i deres e-mails.
> > Hent gratis SPAMfighter her: www.spamfighter.dk
> >
> >
>

Friday, February 10, 2012

Can I keep the border of an image visible all the time?

Here is my problem. I have a series of checkmark images in a table that have
the visibility toggled with an expression. That works fine, however, the
border around the image is not displayed if the image is not. I need to have
a "grid" appearance because the majority of times these images will not be
shown, but I need to to indicate its placement.
Any suggestions would be appreciated.
Thank you,
BobInstead of placing the image directly on a table column, First place a
rectangle in the table column, and then the image in the rectangle, and set
the properties on the rectangle to show its borders, and with your toggle,
since your are only toggling the visiblity of the image, the rectangle should
always be visible.
"Bob" wrote:
> Here is my problem. I have a series of checkmark images in a table that have
> the visibility toggled with an expression. That works fine, however, the
> border around the image is not displayed if the image is not. I need to have
> a "grid" appearance because the majority of times these images will not be
> shown, but I need to to indicate its placement.
> Any suggestions would be appreciated.
> Thank you,
> Bob