Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Wednesday, March 28, 2012

how to asssign string variable to SqlDbType

i have string variable as,

String str="Int";

now, while assigning sql parameters, i want

param.SqlDBType=SqlDBType.Int;

but, value of Int is dynamic. it may be string or double so,

i want it to be as,

param.SqlDBType=(SqlDBType)str;

but its not acceptable(its invalid cast).

in any way can i do it and how?

regards--

The SqlDBType is not the value you are passing to the database, rather it is the data type. Therefore this must match that of your table column data type.

If your column is a varchar you would assign SqlDBType.Varchar or of it is an Int you would assign SqlDBType.Int.

To assign the actual value to the parameter you use the Value property.

e.g. param.Value = <the value you want to assign to the parameter>

How to assign string value to TEXT output parameter of a stored procedure?

Hello,

I am currently trying to assign some string to a TEXT output parameter
of a stored procedure.

The basic structure of the stored procedure looks like this:

-- 8< --
CREATE PROCEDURE owner.StoredProc
(
@.blob_data image,
@.clob_data text OUTPUT
)
AS
INSERT INTO Table (blob_data, clob_data) VALUES \
(@.blob_data, @.clob_data);
GO
-- 8< --

My previous attempts include using the convert function to convert a
string into a TEXT data type:
SET @.clob_data = CONVERT(text, 'This is a test');

Unfortunately, this leads to the following error: "Error 409: The
assignment operator operation cannot take a text data type as an argument."

Is there any alternative available to make an assignment to a TEXT
output parameter?

Regards,
ThiloIs there a reason you can't just do a select on it?

Monday, March 26, 2012

How to apply For loop here

Problem Description:

I have 5 fields in my report.
4 string type and 1 Date.
4 String type are : Unit , Periods , Grade and Demand
and 1 is Date

I would like to apply a loop which eventually sum up the value of the last field.
Before I explain it furthur I would like to add that all the string type has
multiple value in it.

Description :

I would like sum up Demand for each Grade per period per Unit.

For Example

Unit 1
Date ( monthly)1
Grade 1
Period 1 Total Demand
Period 2 Total Demand
Period 3 Total Demand

Date2
Grade 2
Period 1 Total Demand
Period 2 Total Demand
Period 3 Total Demand

I think this involves couple of For loops , Sorry but not familier with
Syntax that much.

Thanks

AbhisarDo you want to sum the field Demand which is of String type?|||Yes ,
I want to sum field demand. of string type.
so it looks like.

For loop unit ...select one unit in that string array.
then Start for loop to select the date from the Date array ( which in monthly format)
Then for loop to select the grade (string array)....
and then for each period( 3 in it ) it will show me total demand..

The actual data looks like...

Unit date grade period demand
------------------
ew 333 rrr Day 44
ew 333 rrr Eve 55
ew 333 rrr Night 22
...
...
...
ew 645 rrr Day 43
ew 645 rrr Eve 33
ew 645 rrr Night 21

Like wise
diff date .....

I would like to see

for
unit (ew) date(333) for grade(rrr)
on period (Day) total demand
(Eve) total demand
(Night) Total demand

because there are lot of person works on the same date, same unit, same grade
same three period but different demand.
I want to sum up all the demand and write a summary.

I hope I am able to explain my problem to all of u this time.

Thanks|||You can try this in the formula

numbervar eveCount;
numbervar DayCount;
whilePringtingRecords;
if {period}="Day"
DayCount:=DayCount+tonumber({Demand})
else if {period}="Eve"
EveCount:=EveCount+tonumber({Demand});|||Sorry Guys bot not working at all.

Ok , Let me reframe it to one more example.

there are 5 fields , the values in 4 of the fields are not changing at all , only in the 5th field is changing.
For example

1st field 2nd Field 3rd Field 4rth Field 5th Field

xxx rrrr tttt cccc 33
xxx rrrr tttt cccc 44
xxx rrrr tttt cccc 55

I just want to see

xxx rrrr tttt cccc 132 (total)

just in one line.

any ideas now.

Thanks|||If so, then why dont you try to write a query

Select field1,field2,field3,field4,sum(convert(numeric,field5)) from table group by
field1,field2,field3,field4
and design the report using this query

Wednesday, March 21, 2012

How to allow apostrophes in string parameters

I have a few reports that contain a customer name parameter. I have
just realized that when a customer name contains a single-quote
(apostrophe), reporting services thinks that it's an unclosed string
and I receive an error.
The error I get -
"An error has occurred during report processing.
Query execution failed for data set '....'.
Line 1: Incorrect syntax near 's'.
Unclosed quotation mark before the character string"."
I know that I probably need to 'escape' the single quote, but I am
unclear if I can do this on the data tab in report designer or if I
have to do this through my views/stored procs in sql server. After
determining where to make the change, I will also need to know what
the correct syntax is.
Thanks so much for your help.
CrystalOn Feb 14, 11:59=A0am, Just Another Reporter <Crystal.War...@.gmail.com>
wrote:
> I have a few reports that contain a customer name parameter. =A0I have
> just realized that when a customer name contains a single-quote
> (apostrophe), reporting services thinks that it's an unclosed string
> and I receive an error.
> The error I get -
> "An error has occurred during report processing.
> Query execution failed for data set '....'.
> Line 1: Incorrect syntax near 's'.
> Unclosed quotation mark before the character string"."
> I know that I probably need to 'escape' the single quote, but I am
> unclear if I can do this on the data tab in report designer or if I
> have to do this through my views/stored procs in sql server. =A0After
> determining where to make the change, I will also need to know what
> the correct syntax is.
> Thanks so much for your help.
> Crystal
Go to the Data tab, and click the Properties button [...] for the
Dataset. Under the Parameters tab, you will see mappings between the
parameters used in the dataset, mapped to the Report Parameters. Note
that these are expressions, so you can put your own code in here to
"escape" the single quote.
What you will want to do is do is something like:
@.Pararm =3DReplace( Parameters!Param.Value, "'", "''" )
-- Scott