Tuesday, March 20, 2012

Retrieving lables from database

I'm creating lots of reports containing similiar lables, "Username", "Country", "Date of birth" etc. For some reason people tend to wanna change these lables over time so "Date of birth" becomes "Birthdate" or something. As I'm doing it now, I'll have to edit all my reports containing "Date of birth" when this happens.

So, instead I'll try using some kind of databasetable containing all the strings. However, I'm not sure about the best way of implementing this. A language-code could be great in a table like this, but lets skip it for this small example. Lets say the DB-table only contained two columns, "ID" and "String". Then one way of doing this would be to create one dataset for each string/lable, i.e. "Select String from StringTable where ID=23". Then use "=First(Fields!String.Value)" for one lable in the report. However, it would be a bit messy with one dataset for each lable.

Is there some way in a lable expression to, instead of "First", define a row with a given ID, i.e. "=Fields!String.Value where ID = 23" ? Or how would you solve this "lable problem"?

Regards Andreas

If you are displaying the whole table you can use the INFORMATION_SCHEMA.COLUMNS view to get the information back, simply query on the table_name and you will get all the columns of the table back.

HTH, jens Suessmeyer.

http://www.sqlserver2005.de|||If I understand you correct, you reffer to having one column in the table per string/lable? This wasn't my intention. My intention was to have all strings/lables in the same column and identified by an ID. Do you get what I mean?|||Mhmm, yes I thought so, try to execute the following query (on the adventureworks database)

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS

WHERE Table_NAMe = 'Log'

which results in:

LogID
EventID
Priority
Severity
Title
Timestamp
MachineName
AppDomainName
ProcessID
ProcessName
ThreadName
Win32ThreadId
Message
FormattedMessage

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

No comments:

Post a Comment