Showing posts with label named. Show all posts
Showing posts with label named. Show all posts

Wednesday, March 21, 2012

REPLACE Integers with Text Data

I am working with a database named “Documents” that contains 4 categories of text documents, each having its own number designation in an integer datatype column named SectionTypeId:

1 = Text

2 = Report

3 = Background

4 = Index

I would like to create a new column named “DocType” in which the integer data type for each document is replaced with a varchar data type letter (1 = T, 2 = R, 3 = B, 4 = I).I was able to easily create the new column and cast the data type from integer to varchar:

--CREATE NEW COLUMN “DocType” WITH VARCHAR DATATYPE

ALTER TABLE FullDocuments ADD DocType VARCHAR(1) NULL

Go

--UPDATE NEW COLUMN WITH CAST STRING

UPDATE FullDocuments SET DocType = CAST(SectionTypeID AS VARCHAR(1))

Go

But I have problems with the REPLACE method for replacing the numbers with letters.First I tried this based on the examples in MSDN Library:

--REPLACE NUMBERS WITH LETTERS

UPDATE Fulldocuments REPLACE (DocType,"1","T")

Which produced an error message: “Incorrect syntax near 'REPLACE'.”

Thinking that the datatype may be the problem, I tried this to convert to DT_WSTR data type prior to replace:

UPDATE Fulldocuments REPLACE ((DT_WSTR,1)DocType,"1","T")

Which produced the same error message: “Incorrect syntax near 'REPLACE'.”

I have never done a REPLACE before, so any suggestions for accomplishing this would be appreciated.

Your UPDATE statement syntax is incorrect. And the 2nd syntax where you are trying to cast to DT_WSTR is not a valid SQL syntax also. See SQL Server Books Online for the complete UPDATE statement syntax and examples. UPDATE statement consists of SET, FROM and WHERE clauses. You are missing the SET clause. And you should use single-quotes preferably for string literals otherwise you will get errors most of the time depending on your SET options. Modify your update statement to:

UPDATE Fulldocuments SET DocType = REPLACE (DocType,'1','T')

But it doesn't seem like you want to create this DocType column in the first place. You should create a separate lookup table that contains the ids and description or type. You can then join with that table based on your ID value to get the description. This is much more flexible approach that doing it your way.

|||Thanks for correcting my syntax and the advice about creating a separate lookup table.

Tuesday, March 20, 2012

RepeatWith property doesn't appear to work

The RepeatWith property doesn't appear to work. I have named an element (a
table) that in is the same ReportItems collection but the object is only
displayed on the first page of the report.
ThanksIt doesn't work in designer preview or PDF but it will work in HTML.
--
Brian Welcker
Group Program Manager
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Bryan Bullard" <reply@.to.group.com> wrote in message
news:OgOArdXVEHA.3512@.TK2MSFTNGP12.phx.gbl...
> The RepeatWith property doesn't appear to work. I have named an element
(a
> table) that in is the same ReportItems collection but the object is only
> displayed on the first page of the report.
> Thanks
>|||"Brian Welcker [MSFT]" <bwelcker@.online.microsoft.com> wrote in message
news:e8ZawZzVEHA.2564@.TK2MSFTNGP11.phx.gbl...
> "Bryan Bullard" <reply@.to.group.com> wrote in message
> news:OgOArdXVEHA.3512@.TK2MSFTNGP12.phx.gbl...
> > The RepeatWith property doesn't appear to work. I have named an element
> (a
> > table) that in is the same ReportItems collection but the object is only
> > displayed on the first page of the report.
> It doesn't work in designer preview or PDF but it will work in HTML.
Why not? Will this be corrected soon? I need this functionality. Is there
a work around?|||You can put your contents to repeat in a header / footer and set them to
repeat on new pages.
--
Brian Welcker
Group Program Manager
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Bryan Bullard" <reply@.to.group.com> wrote in message
news:ua%23jgX5VEHA.3988@.tk2msftngp13.phx.gbl...
> "Brian Welcker [MSFT]" <bwelcker@.online.microsoft.com> wrote in message
> news:e8ZawZzVEHA.2564@.TK2MSFTNGP11.phx.gbl...
> > "Bryan Bullard" <reply@.to.group.com> wrote in message
> > news:OgOArdXVEHA.3512@.TK2MSFTNGP12.phx.gbl...
> > > The RepeatWith property doesn't appear to work. I have named an
element
> > (a
> > > table) that in is the same ReportItems collection but the object is
only
> > > displayed on the first page of the report.
> > It doesn't work in designer preview or PDF but it will work in HTML.
> Why not? Will this be corrected soon? I need this functionality. Is
there
> a work around?
>
>|||"Brian Welcker [MSFT]" <bwelcker@.online.microsoft.com> wrote in message
news:#YAvnS9VEHA.4048@.TK2MSFTNGP12.phx.gbl...
> You can put your contents to repeat in a header / footer and set them to
> repeat on new pages.
This doesn't work because it appears that you cannot have dynamic content in
the report header and footer. Is there another work around?|||Not the page header and footer. The table or group header and footer.
--
Brian Welcker
Group Program Manager
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Bryan Bullard" <reply@.to.group.com> wrote in message
news:uhFf25FWEHA.2816@.TK2MSFTNGP11.phx.gbl...
> "Brian Welcker [MSFT]" <bwelcker@.online.microsoft.com> wrote in message
> news:#YAvnS9VEHA.4048@.TK2MSFTNGP12.phx.gbl...
>> You can put your contents to repeat in a header / footer and set them to
>> repeat on new pages.
> This doesn't work because it appears that you cannot have dynamic content
> in
> the report header and footer. Is there another work around?
>|||"Brian Welcker [MSFT]" <bwelcker@.online.microsoft.com> wrote in message
news:##T$w8FWEHA.3596@.tk2msftngp13.phx.gbl...
> Not the page header and footer. The table or group header and footer.
Okay, Thanks.

Monday, February 20, 2012

Rendering report fields

Hi,

I am designing a report that creates a letter to send to a named individual. To accomodate different address lengths, additional fields have been added to the db. Is there a method by which if an address filed is empty, it does not display in the redered report and the fields below it are moved up to close the gap?

Any one any ideas?

Thanks

Yes, you can use just one textbox with line feed and carriage return characters appended in between conditionally something like this:

Fields!Address1.Value &

IIf(Fields!Address2.Value <> "", Chr(10) & Chr(13) & Fields!Address1.Value, "") &

IIf(Fields!City.Value <> "", Chr(10) & Chr(13) & Fields!City.Value, "") &

IIf(Fields!State.Value <> "", Chr(10) & Chr(13) & Fields!State.Value, "")

.....

Shyam

|||

Hi Shyam,

Thank you for your response. I am new to this and am not sure how the coding fits in. Below is what I have currently:

=First(Fields!Name.Value)
=First(Fields!Address1.Value)
=First(Fields!Address2.Value)
=First(Fields!Address3.Value)
=First(Fields!Town.Value)
=First(Fields!County.Value)
=First(Fields!Post_Code.Value)

A further example of where your code fits in would be a great help.

Thanks

|||

I guess you have 7 textboxes one below another. Now, delete the bottom 6 textboxes and put this expression in the top textbox:

=First(Fields!Name.Value) &

IIf(First(Fields!Address1.Value) <> "", Chr(10) & Chr(13) & First(Fields!Address1.Value), "") &

IIf(First(Fields!Address2.Value) <> "", Chr(10) & Chr(13) & First(Fields!Address2.Value), "") &

IIf(First(Fields!Address3.Value) <> "", Chr(10) & Chr(13) & First(Fields!Address3.Value), "") &

IIf(First(Fields!Town.Value) <> "", Chr(10) & Chr(13) & First(Fields!Town.Value), "") &

IIf(First(Fields!County.Value) <> "", Chr(10) & Chr(13) & First(Fields!County.Value), "") &

IIf(First(Fields!Post_Code.Value) <> "", Chr(10) & Chr(13) & First(Fields!Post_Code.Value), "") &

Shyam

|||

That works a treat.

Thanks for your help

|||

Hi Shyam,

That works fine in the dev studio but when rendered from the reporting server, all fields are rendered on the same line. Is there a fix for this?

Thanks