Showing posts with label tables. Show all posts
Showing posts with label tables. Show all posts

Monday, March 26, 2012

Dynamic Query

I am trying to write some code to go through all the tables in my database
and do a row count. What I have done so far is open a cursor to sysobject
and loop round the tables in it. Then I am building a query in a string
"SELECT COUNT(*) FROM" + tablename . My next step is to EXEC the created
string. The problem is getting the result back from the count, can anybody
tell me how I do this?
thanks
Gav--Try this
Use Northwind
Declare @.sql nvarchar(1000), @.tablename nvarchar(100) ,@.Count int
SET @.tablename = 'Employees'
SET @.sql = 'SELECT @.Count =COUNT(*) FROM ' + @.tablename
exec sp_executeSQL @.sql, N'@.Count int OUTPUT' , @.Count OUTPUT
print @.Count
~Bala|||Select object_name(id), rows from sysindexes where indid<1
Madhivanan|||<balacr@.gmail.com> wrote in message
news:1111658074.290946.83940@.f14g2000cwb.googlegroups.com...
> --Try this
> Use Northwind
> Declare @.sql nvarchar(1000), @.tablename nvarchar(100) ,@.Count int
> SET @.tablename = 'Employees'
> SET @.sql = 'SELECT @.Count =COUNT(*) FROM ' + @.tablename
> exec sp_executeSQL @.sql, N'@.Count int OUTPUT' , @.Count OUTPUT
> print @.Count
> ~Bala
>
Ths was great until I move the code from my Dev box to one of the servers
I want to run this on. Seems the sp_executeSQL does not exist, any ideas
why?
Gav|||Which version of SQL server are you using?
I am not sure whether 'sp_ExecuteSQL' was on SQL 7
Bala|||They are all on the same version SQL 2000 SP3a.. Only difference is the box
I am now trying to run it on is a SAP database server, box I wrote it on was
not.
Gav
<balacr@.gmail.com> wrote in message
news:1111665107.148760.270850@.g14g2000cwa.googlegroups.com...
> Which version of SQL server are you using?
> I am not sure whether 'sp_ExecuteSQL' was on SQL 7
> Bala
>|||Can you tell me the exact error that you are getting?|||Could not find stored procedure 'sp_executeSQL'.
<balacr@.gmail.com> wrote in message
news:1111669257.820312.152460@.l41g2000cwc.googlegroups.com...
> Can you tell me the exact error that you are getting?
>|||My guess is that the server is case sensitive. The name of the procedure is
sp_executesql, not
sp_executeSQL.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Gav" <gavin.metcalfe@.nospam.portakabin.com> wrote in message
news:d1ufp2$teb$1@.newsreaderg1.core.theplanet.net...
> Could not find stored procedure 'sp_executeSQL'.
> <balacr@.gmail.com> wrote in message
> news:1111669257.820312.152460@.l41g2000cwc.googlegroups.com...
>|||Spot on. Thanks to everyone for their help. :o)
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OwvlAeHMFHA.576@.TK2MSFTNGP15.phx.gbl...
> My guess is that the server is case sensitive. The name of the procedure
is sp_executesql, not
> sp_executeSQL.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Gav" <gavin.metcalfe@.nospam.portakabin.com> wrote in message
> news:d1ufp2$teb$1@.newsreaderg1.core.theplanet.net...
>

Thursday, March 22, 2012

Dynamic Parameter

My DB has 3 tables Employee, Department, Job
I want to create a report with two parameters.
Parameter 1 Options: Employee, Department or Job
Parameter 2 Options: When user selects Employee from parameter 1, all
employee names will be made available to select in parameter 2, When user
selects department from parameter 1, all department names will be made
available to select in parameter 2.
How would one doe this? Any help is appreciated.I did this for a Northwind DB. Here is how my RDL looked. Multiple queries
and data sets returned.
I changed the names of my data source and data sets. It should still work
against a Northwind DB.
<?xml version="1.0" encoding="utf-8"?>
<Report
xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini
tion"
xmlns:rd="">http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<DataSources>
<DataSource Name="ds1">
<rd:DataSourceID>2122d420-3823-467b-8d49-89744c792684</rd:DataSourceID>
<ConnectionProperties>
<DataProvider>SQL</DataProvider>
<ConnectString>data source=servername;initial
catalog=Northwind</ConnectString>
</ConnectionProperties>
</DataSource>
</DataSources>
<rd:ReportID>48c77212-85fb-46c9-9347-e0ecf74aa394</rd:ReportID>
<Body>
<ReportItems>
<Textbox Name="textbox_2">
<Style>
<BackgroundColor>Yellow</BackgroundColor>
<TextAlign>Left</TextAlign>
<FontSize>9pt</FontSize>
</Style>
<Height>.5 in</Height>
<Width>3 in</Width>
<CanGrow>true</CanGrow>
<Value>=Fields!TestResult.Value
+ "********Parameters CustomerIDParam Value: " +
Parameters!CustomerIDParam.Value
+ "********Parameters EmployeeIDParam Value: " +
Str(Parameters!EmployeeIDParam.Value)
</Value>
<Top>.5 in</Top>
<Left>0 in</Left>
</Textbox>
<Textbox Name="textbox_1">
<Style>
<BackgroundColor>Red</BackgroundColor>
<FontSize>14pt</FontSize>
</Style>
<Height>.5 in</Height>
<Width>3 in</Width>
<CanGrow>true</CanGrow>
<Value>Test Result Below:</Value>
<Top>0 in</Top>
<Left>0 in</Left>
</Textbox>
</ReportItems>
<Height>1.705in</Height>
</Body>
<rd:DrawGrid>true</rd:DrawGrid>
<DataSets>
<DataSet Name="mydataset">
<Fields>
<Field Name="TestResult">
<DataField>TestResult</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="CustomerID">
<DataField>CustomerID</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="EmployeeID">
<DataField>EmployeeID</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
</Fields>
<Query>
<DataSourceName>ds1</DataSourceName>
<CommandType>Text</CommandType>
<CommandText>SELECT * , 'Test Passed' as "TestResult" FROM Orders
WHERE EmployeeID = @.EmployeeIDParam AND CustomerID =@.CustomerIDParam</CommandText>
<rd:UseGenericDesigner>true</rd:UseGenericDesigner>
<QueryParameters>
<QueryParameter Name="@.EmployeeIDParam">
<Value>=Parameters!EmployeeIDParam.Value</Value>
</QueryParameter>
<QueryParameter Name="@.CustomerIDParam">
<Value>=Parameters!CustomerIDParam.Value</Value>
</QueryParameter>
</QueryParameters>
</Query>
</DataSet>
<DataSet Name="mydataset2">
<Fields>
<Field Name="EmployeeID">
<DataField>EmployeeID</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
</Fields>
<Query>
<DataSourceName>ds1</DataSourceName>
<CommandType>Text</CommandType>
<CommandText>SELECT DISTINCT EmployeeID FROM Employees
ORDER BY EmployeeID ASC</CommandText>
<rd:UseGenericDesigner>true</rd:UseGenericDesigner>
</Query>
</DataSet>
<DataSet Name="mydataset3">
<Fields>
<Field Name="CustomerID">
<DataField>CustomerID</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
<Query>
<DataSourceName>ds1</DataSourceName>
<CommandType>Text</CommandType>
<CommandText>SELECT DISTINCT CustomerID FROM Orders
WHERE EmployeeID = @.EmployeeIDParam ORDER BY CustomerID ASC</CommandText>
<rd:UseGenericDesigner>true</rd:UseGenericDesigner>
<QueryParameters>
<QueryParameter Name="@.EmployeeIDParam">
<Value>=Parameters!EmployeeIDParam.Value</Value>
</QueryParameter>
</QueryParameters>
</Query>
</DataSet>
</DataSets>
<Language>en-US</Language>
<RightMargin>1in</RightMargin>
<BottomMargin>1in</BottomMargin>
<TopMargin>1in</TopMargin>
<rd:SnapToGrid>true</rd:SnapToGrid>
<Width>5in</Width>
<LeftMargin>1in</LeftMargin>
<ReportParameters>
<ReportParameter Name="EmployeeID">
<DataType>Integer</DataType>
<DefaultValue>
<Values>
<Value>1</Value>
</Values>
</DefaultValue>
<ValidValues>
<DataSetReference>
<DataSetName>mydataset2</DataSetName>
<ValueField>EmployeeID</ValueField>
<LabelField>EmployeeID</LabelField>
</DataSetReference>
</ValidValues>
<Prompt>Employee ID :</Prompt>
</ReportParameter>
<ReportParameter Name="EmployeeIDParam">
<DataType>Integer</DataType>
<DefaultValue>
<Values>
<Value>=Parameters!EmployeeID.Value</Value>
</Values>
</DefaultValue>
<Prompt> </Prompt>
</ReportParameter>
<ReportParameter Name="CustomerIDParam">
<DataType>String</DataType>
<DefaultValue>
<Values>
<Value>VINET</Value>
</Values>
</DefaultValue>
<ValidValues>
<DataSetReference>
<DataSetName>mydataset3</DataSetName>
<ValueField>CustomerID</ValueField>
<LabelField>CustomerID</LabelField>
</DataSetReference>
</ValidValues>
<Prompt>Customer ID :</Prompt>
</ReportParameter>
</ReportParameters>
</Report>
--
| Thread-Topic: Dynamic Parameter
| thread-index: AcUFhs+wyP3Cs1ONTxSLxYdNcM59XQ==| X-WBNR-Posting-Host: 70.66.0.254
| From: "=?Utf-8?B?U0FjYW51Y2s=?=" <SAcanuck@.discussions.microsoft.com>
| Subject: Dynamic Parameter
| Date: Fri, 28 Jan 2005 14:15:01 -0800
| Lines: 12
| Message-ID: <AE5AB9C9-7340-4ED3-9EC6-3F5DB22834AA@.microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.sqlserver.reportingsvcs
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
| Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.reportingsvcs:41264
| X-Tomcat-NG: microsoft.public.sqlserver.reportingsvcs
|
| My DB has 3 tables Employee, Department, Job
|
| I want to create a report with two parameters.
|
| Parameter 1 Options: Employee, Department or Job
|
| Parameter 2 Options: When user selects Employee from parameter 1, all
| employee names will be made available to select in parameter 2, When
user
| selects department from parameter 1, all department names will be made
| available to select in parameter 2.
|
| How would one doe this? Any help is appreciated.
||||It is not necessary to dive into this RDL code.
Go to the online help from Reporting Services. There is a chapter Create
Report (or similare) and there is a description of using Parameters. On the
end of this article is your question answered in the best way.
""Brad Syputa - MS"" wrote:
> I did this for a Northwind DB. Here is how my RDL looked. Multiple queries
> and data sets returned.
> I changed the names of my data source and data sets. It should still work
> against a Northwind DB.
> <?xml version="1.0" encoding="utf-8"?>
> <Report
> xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini
> tion"
> xmlns:rd="">http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
> <DataSources>
> <DataSource Name="ds1">
> <rd:DataSourceID>2122d420-3823-467b-8d49-89744c792684</rd:DataSourceID>
> <ConnectionProperties>
> <DataProvider>SQL</DataProvider>
> <ConnectString>data source=servername;initial
> catalog=Northwind</ConnectString>
> </ConnectionProperties>
> </DataSource>
> </DataSources>
> <rd:ReportID>48c77212-85fb-46c9-9347-e0ecf74aa394</rd:ReportID>
> <Body>
> <ReportItems>
> <Textbox Name="textbox_2">
> <Style>
> <BackgroundColor>Yellow</BackgroundColor>
> <TextAlign>Left</TextAlign>
> <FontSize>9pt</FontSize>
> </Style>
> <Height>.5 in</Height>
> <Width>3 in</Width>
> <CanGrow>true</CanGrow>
> <Value>=Fields!TestResult.Value
> + "********Parameters CustomerIDParam Value: " +
> Parameters!CustomerIDParam.Value
> + "********Parameters EmployeeIDParam Value: " +
> Str(Parameters!EmployeeIDParam.Value)
> </Value>
> <Top>.5 in</Top>
> <Left>0 in</Left>
> </Textbox>
> <Textbox Name="textbox_1">
> <Style>
> <BackgroundColor>Red</BackgroundColor>
> <FontSize>14pt</FontSize>
> </Style>
> <Height>.5 in</Height>
> <Width>3 in</Width>
> <CanGrow>true</CanGrow>
> <Value>Test Result Below:</Value>
> <Top>0 in</Top>
> <Left>0 in</Left>
> </Textbox>
> </ReportItems>
> <Height>1.705in</Height>
> </Body>
> <rd:DrawGrid>true</rd:DrawGrid>
> <DataSets>
> <DataSet Name="mydataset">
> <Fields>
> <Field Name="TestResult">
> <DataField>TestResult</DataField>
> <rd:TypeName>System.String</rd:TypeName>
> </Field>
> <Field Name="CustomerID">
> <DataField>CustomerID</DataField>
> <rd:TypeName>System.String</rd:TypeName>
> </Field>
> <Field Name="EmployeeID">
> <DataField>EmployeeID</DataField>
> <rd:TypeName>System.Int32</rd:TypeName>
> </Field>
> </Fields>
> <Query>
> <DataSourceName>ds1</DataSourceName>
> <CommandType>Text</CommandType>
> <CommandText>SELECT * , 'Test Passed' as "TestResult" FROM Orders
> WHERE EmployeeID = @.EmployeeIDParam AND CustomerID => @.CustomerIDParam</CommandText>
> <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> <QueryParameters>
> <QueryParameter Name="@.EmployeeIDParam">
> <Value>=Parameters!EmployeeIDParam.Value</Value>
> </QueryParameter>
> <QueryParameter Name="@.CustomerIDParam">
> <Value>=Parameters!CustomerIDParam.Value</Value>
> </QueryParameter>
> </QueryParameters>
> </Query>
> </DataSet>
> <DataSet Name="mydataset2">
> <Fields>
> <Field Name="EmployeeID">
> <DataField>EmployeeID</DataField>
> <rd:TypeName>System.Int32</rd:TypeName>
> </Field>
> </Fields>
> <Query>
> <DataSourceName>ds1</DataSourceName>
> <CommandType>Text</CommandType>
> <CommandText>SELECT DISTINCT EmployeeID FROM Employees
> ORDER BY EmployeeID ASC</CommandText>
> <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> </Query>
> </DataSet>
> <DataSet Name="mydataset3">
> <Fields>
> <Field Name="CustomerID">
> <DataField>CustomerID</DataField>
> <rd:TypeName>System.String</rd:TypeName>
> </Field>
> </Fields>
> <Query>
> <DataSourceName>ds1</DataSourceName>
> <CommandType>Text</CommandType>
> <CommandText>SELECT DISTINCT CustomerID FROM Orders
> WHERE EmployeeID = @.EmployeeIDParam ORDER BY CustomerID ASC</CommandText>
> <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> <QueryParameters>
> <QueryParameter Name="@.EmployeeIDParam">
> <Value>=Parameters!EmployeeIDParam.Value</Value>
> </QueryParameter>
> </QueryParameters>
> </Query>
> </DataSet>
> </DataSets>
> <Language>en-US</Language>
> <RightMargin>1in</RightMargin>
> <BottomMargin>1in</BottomMargin>
> <TopMargin>1in</TopMargin>
> <rd:SnapToGrid>true</rd:SnapToGrid>
> <Width>5in</Width>
> <LeftMargin>1in</LeftMargin>
> <ReportParameters>
> <ReportParameter Name="EmployeeID">
> <DataType>Integer</DataType>
> <DefaultValue>
> <Values>
> <Value>1</Value>
> </Values>
> </DefaultValue>
> <ValidValues>
> <DataSetReference>
> <DataSetName>mydataset2</DataSetName>
> <ValueField>EmployeeID</ValueField>
> <LabelField>EmployeeID</LabelField>
> </DataSetReference>
> </ValidValues>
> <Prompt>Employee ID :</Prompt>
> </ReportParameter>
> <ReportParameter Name="EmployeeIDParam">
> <DataType>Integer</DataType>
> <DefaultValue>
> <Values>
> <Value>=Parameters!EmployeeID.Value</Value>
> </Values>
> </DefaultValue>
> <Prompt> </Prompt>
> </ReportParameter>
> <ReportParameter Name="CustomerIDParam">
> <DataType>String</DataType>
> <DefaultValue>
> <Values>
> <Value>VINET</Value>
> </Values>
> </DefaultValue>
> <ValidValues>
> <DataSetReference>
> <DataSetName>mydataset3</DataSetName>
> <ValueField>CustomerID</ValueField>
> <LabelField>CustomerID</LabelField>
> </DataSetReference>
> </ValidValues>
> <Prompt>Customer ID :</Prompt>
> </ReportParameter>
> </ReportParameters>
> </Report>
> --
> | Thread-Topic: Dynamic Parameter
> | thread-index: AcUFhs+wyP3Cs1ONTxSLxYdNcM59XQ==> | X-WBNR-Posting-Host: 70.66.0.254
> | From: "=?Utf-8?B?U0FjYW51Y2s=?=" <SAcanuck@.discussions.microsoft.com>
> | Subject: Dynamic Parameter
> | Date: Fri, 28 Jan 2005 14:15:01 -0800
> | Lines: 12
> | Message-ID: <AE5AB9C9-7340-4ED3-9EC6-3F5DB22834AA@.microsoft.com>
> | MIME-Version: 1.0
> | Content-Type: text/plain;
> | charset="Utf-8"
> | Content-Transfer-Encoding: 7bit
> | X-Newsreader: Microsoft CDO for Windows 2000
> | Content-Class: urn:content-classes:message
> | Importance: normal
> | Priority: normal
> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> | Newsgroups: microsoft.public.sqlserver.reportingsvcs
> | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
> | Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
> | Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.reportingsvcs:41264
> | X-Tomcat-NG: microsoft.public.sqlserver.reportingsvcs
> |
> | My DB has 3 tables Employee, Department, Job
> |
> | I want to create a report with two parameters.
> |
> | Parameter 1 Options: Employee, Department or Job
> |
> | Parameter 2 Options: When user selects Employee from parameter 1, all
> | employee names will be made available to select in parameter 2, When
> user
> | selects department from parameter 1, all department names will be made
> | available to select in parameter 2.
> |
> | How would one doe this? Any help is appreciated.
> |
>|||I had a look at the reporting services books online and it had a description
on how to use a basiv dynamic parameter...my requirement is a bit more
advanced than the given example.
"Dev Main" wrote:
> It is not necessary to dive into this RDL code.
> Go to the online help from Reporting Services. There is a chapter Create
> Report (or similare) and there is a description of using Parameters. On the
> end of this article is your question answered in the best way.
>
> ""Brad Syputa - MS"" wrote:
> > I did this for a Northwind DB. Here is how my RDL looked. Multiple queries
> > and data sets returned.
> >
> > I changed the names of my data source and data sets. It should still work
> > against a Northwind DB.
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <Report
> > xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini
> > tion"
> > xmlns:rd="">http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
> > <DataSources>
> > <DataSource Name="ds1">
> >
> > <rd:DataSourceID>2122d420-3823-467b-8d49-89744c792684</rd:DataSourceID>
> > <ConnectionProperties>
> > <DataProvider>SQL</DataProvider>
> > <ConnectString>data source=servername;initial
> > catalog=Northwind</ConnectString>
> > </ConnectionProperties>
> > </DataSource>
> > </DataSources>
> > <rd:ReportID>48c77212-85fb-46c9-9347-e0ecf74aa394</rd:ReportID>
> > <Body>
> > <ReportItems>
> > <Textbox Name="textbox_2">
> > <Style>
> > <BackgroundColor>Yellow</BackgroundColor>
> > <TextAlign>Left</TextAlign>
> > <FontSize>9pt</FontSize>
> > </Style>
> > <Height>.5 in</Height>
> > <Width>3 in</Width>
> > <CanGrow>true</CanGrow>
> > <Value>=Fields!TestResult.Value
> > + "********Parameters CustomerIDParam Value: " +
> > Parameters!CustomerIDParam.Value
> > + "********Parameters EmployeeIDParam Value: " +
> > Str(Parameters!EmployeeIDParam.Value)
> > </Value>
> > <Top>.5 in</Top>
> > <Left>0 in</Left>
> > </Textbox>
> > <Textbox Name="textbox_1">
> > <Style>
> > <BackgroundColor>Red</BackgroundColor>
> > <FontSize>14pt</FontSize>
> > </Style>
> > <Height>.5 in</Height>
> > <Width>3 in</Width>
> > <CanGrow>true</CanGrow>
> > <Value>Test Result Below:</Value>
> > <Top>0 in</Top>
> > <Left>0 in</Left>
> > </Textbox>
> > </ReportItems>
> > <Height>1.705in</Height>
> > </Body>
> > <rd:DrawGrid>true</rd:DrawGrid>
> > <DataSets>
> > <DataSet Name="mydataset">
> > <Fields>
> > <Field Name="TestResult">
> > <DataField>TestResult</DataField>
> > <rd:TypeName>System.String</rd:TypeName>
> > </Field>
> > <Field Name="CustomerID">
> > <DataField>CustomerID</DataField>
> > <rd:TypeName>System.String</rd:TypeName>
> > </Field>
> > <Field Name="EmployeeID">
> > <DataField>EmployeeID</DataField>
> > <rd:TypeName>System.Int32</rd:TypeName>
> > </Field>
> > </Fields>
> > <Query>
> > <DataSourceName>ds1</DataSourceName>
> > <CommandType>Text</CommandType>
> > <CommandText>SELECT * , 'Test Passed' as "TestResult" FROM Orders
> > WHERE EmployeeID = @.EmployeeIDParam AND CustomerID => > @.CustomerIDParam</CommandText>
> > <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> > <QueryParameters>
> > <QueryParameter Name="@.EmployeeIDParam">
> > <Value>=Parameters!EmployeeIDParam.Value</Value>
> > </QueryParameter>
> > <QueryParameter Name="@.CustomerIDParam">
> > <Value>=Parameters!CustomerIDParam.Value</Value>
> > </QueryParameter>
> > </QueryParameters>
> > </Query>
> > </DataSet>
> > <DataSet Name="mydataset2">
> > <Fields>
> > <Field Name="EmployeeID">
> > <DataField>EmployeeID</DataField>
> > <rd:TypeName>System.Int32</rd:TypeName>
> > </Field>
> > </Fields>
> > <Query>
> > <DataSourceName>ds1</DataSourceName>
> > <CommandType>Text</CommandType>
> > <CommandText>SELECT DISTINCT EmployeeID FROM Employees
> > ORDER BY EmployeeID ASC</CommandText>
> > <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> > </Query>
> > </DataSet>
> > <DataSet Name="mydataset3">
> > <Fields>
> > <Field Name="CustomerID">
> > <DataField>CustomerID</DataField>
> > <rd:TypeName>System.String</rd:TypeName>
> > </Field>
> > </Fields>
> > <Query>
> > <DataSourceName>ds1</DataSourceName>
> > <CommandType>Text</CommandType>
> > <CommandText>SELECT DISTINCT CustomerID FROM Orders
> > WHERE EmployeeID = @.EmployeeIDParam ORDER BY CustomerID ASC</CommandText>
> > <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> > <QueryParameters>
> > <QueryParameter Name="@.EmployeeIDParam">
> > <Value>=Parameters!EmployeeIDParam.Value</Value>
> > </QueryParameter>
> > </QueryParameters>
> > </Query>
> > </DataSet>
> > </DataSets>
> > <Language>en-US</Language>
> > <RightMargin>1in</RightMargin>
> > <BottomMargin>1in</BottomMargin>
> > <TopMargin>1in</TopMargin>
> > <rd:SnapToGrid>true</rd:SnapToGrid>
> > <Width>5in</Width>
> > <LeftMargin>1in</LeftMargin>
> > <ReportParameters>
> > <ReportParameter Name="EmployeeID">
> > <DataType>Integer</DataType>
> > <DefaultValue>
> > <Values>
> > <Value>1</Value>
> > </Values>
> > </DefaultValue>
> > <ValidValues>
> > <DataSetReference>
> > <DataSetName>mydataset2</DataSetName>
> > <ValueField>EmployeeID</ValueField>
> > <LabelField>EmployeeID</LabelField>
> > </DataSetReference>
> > </ValidValues>
> > <Prompt>Employee ID :</Prompt>
> > </ReportParameter>
> > <ReportParameter Name="EmployeeIDParam">
> > <DataType>Integer</DataType>
> > <DefaultValue>
> > <Values>
> > <Value>=Parameters!EmployeeID.Value</Value>
> > </Values>
> > </DefaultValue>
> > <Prompt> </Prompt>
> > </ReportParameter>
> > <ReportParameter Name="CustomerIDParam">
> > <DataType>String</DataType>
> > <DefaultValue>
> > <Values>
> > <Value>VINET</Value>
> > </Values>
> > </DefaultValue>
> > <ValidValues>
> > <DataSetReference>
> > <DataSetName>mydataset3</DataSetName>
> > <ValueField>CustomerID</ValueField>
> > <LabelField>CustomerID</LabelField>
> > </DataSetReference>
> > </ValidValues>
> > <Prompt>Customer ID :</Prompt>
> > </ReportParameter>
> > </ReportParameters>
> > </Report>
> > --
> > | Thread-Topic: Dynamic Parameter
> > | thread-index: AcUFhs+wyP3Cs1ONTxSLxYdNcM59XQ==> > | X-WBNR-Posting-Host: 70.66.0.254
> > | From: "=?Utf-8?B?U0FjYW51Y2s=?=" <SAcanuck@.discussions.microsoft.com>
> > | Subject: Dynamic Parameter
> > | Date: Fri, 28 Jan 2005 14:15:01 -0800
> > | Lines: 12
> > | Message-ID: <AE5AB9C9-7340-4ED3-9EC6-3F5DB22834AA@.microsoft.com>
> > | MIME-Version: 1.0
> > | Content-Type: text/plain;
> > | charset="Utf-8"
> > | Content-Transfer-Encoding: 7bit
> > | X-Newsreader: Microsoft CDO for Windows 2000
> > | Content-Class: urn:content-classes:message
> > | Importance: normal
> > | Priority: normal
> > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> > | Newsgroups: microsoft.public.sqlserver.reportingsvcs
> > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
> > | Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
> > | Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.reportingsvcs:41264
> > | X-Tomcat-NG: microsoft.public.sqlserver.reportingsvcs
> > |
> > | My DB has 3 tables Employee, Department, Job
> > |
> > | I want to create a report with two parameters.
> > |
> > | Parameter 1 Options: Employee, Department or Job
> > |
> > | Parameter 2 Options: When user selects Employee from parameter 1, all
> > | employee names will be made available to select in parameter 2, When
> > user
> > | selects department from parameter 1, all department names will be made
> > | available to select in parameter 2.
> > |
> > | How would one doe this? Any help is appreciated.
> > |
> >
> >|||Brad:
I copied the rdl into my designer anf get te following error:
Deserialization failed: The Report element was not found.
""Brad Syputa - MS"" wrote:
> I did this for a Northwind DB. Here is how my RDL looked. Multiple queries
> and data sets returned.
> I changed the names of my data source and data sets. It should still work
> against a Northwind DB.
> <?xml version="1.0" encoding="utf-8"?>
> <Report
> xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini
> tion"
> xmlns:rd="">http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
> <DataSources>
> <DataSource Name="ds1">
> <rd:DataSourceID>2122d420-3823-467b-8d49-89744c792684</rd:DataSourceID>
> <ConnectionProperties>
> <DataProvider>SQL</DataProvider>
> <ConnectString>data source=servername;initial
> catalog=Northwind</ConnectString>
> </ConnectionProperties>
> </DataSource>
> </DataSources>
> <rd:ReportID>48c77212-85fb-46c9-9347-e0ecf74aa394</rd:ReportID>
> <Body>
> <ReportItems>
> <Textbox Name="textbox_2">
> <Style>
> <BackgroundColor>Yellow</BackgroundColor>
> <TextAlign>Left</TextAlign>
> <FontSize>9pt</FontSize>
> </Style>
> <Height>.5 in</Height>
> <Width>3 in</Width>
> <CanGrow>true</CanGrow>
> <Value>=Fields!TestResult.Value
> + "********Parameters CustomerIDParam Value: " +
> Parameters!CustomerIDParam.Value
> + "********Parameters EmployeeIDParam Value: " +
> Str(Parameters!EmployeeIDParam.Value)
> </Value>
> <Top>.5 in</Top>
> <Left>0 in</Left>
> </Textbox>
> <Textbox Name="textbox_1">
> <Style>
> <BackgroundColor>Red</BackgroundColor>
> <FontSize>14pt</FontSize>
> </Style>
> <Height>.5 in</Height>
> <Width>3 in</Width>
> <CanGrow>true</CanGrow>
> <Value>Test Result Below:</Value>
> <Top>0 in</Top>
> <Left>0 in</Left>
> </Textbox>
> </ReportItems>
> <Height>1.705in</Height>
> </Body>
> <rd:DrawGrid>true</rd:DrawGrid>
> <DataSets>
> <DataSet Name="mydataset">
> <Fields>
> <Field Name="TestResult">
> <DataField>TestResult</DataField>
> <rd:TypeName>System.String</rd:TypeName>
> </Field>
> <Field Name="CustomerID">
> <DataField>CustomerID</DataField>
> <rd:TypeName>System.String</rd:TypeName>
> </Field>
> <Field Name="EmployeeID">
> <DataField>EmployeeID</DataField>
> <rd:TypeName>System.Int32</rd:TypeName>
> </Field>
> </Fields>
> <Query>
> <DataSourceName>ds1</DataSourceName>
> <CommandType>Text</CommandType>
> <CommandText>SELECT * , 'Test Passed' as "TestResult" FROM Orders
> WHERE EmployeeID = @.EmployeeIDParam AND CustomerID => @.CustomerIDParam</CommandText>
> <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> <QueryParameters>
> <QueryParameter Name="@.EmployeeIDParam">
> <Value>=Parameters!EmployeeIDParam.Value</Value>
> </QueryParameter>
> <QueryParameter Name="@.CustomerIDParam">
> <Value>=Parameters!CustomerIDParam.Value</Value>
> </QueryParameter>
> </QueryParameters>
> </Query>
> </DataSet>
> <DataSet Name="mydataset2">
> <Fields>
> <Field Name="EmployeeID">
> <DataField>EmployeeID</DataField>
> <rd:TypeName>System.Int32</rd:TypeName>
> </Field>
> </Fields>
> <Query>
> <DataSourceName>ds1</DataSourceName>
> <CommandType>Text</CommandType>
> <CommandText>SELECT DISTINCT EmployeeID FROM Employees
> ORDER BY EmployeeID ASC</CommandText>
> <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> </Query>
> </DataSet>
> <DataSet Name="mydataset3">
> <Fields>
> <Field Name="CustomerID">
> <DataField>CustomerID</DataField>
> <rd:TypeName>System.String</rd:TypeName>
> </Field>
> </Fields>
> <Query>
> <DataSourceName>ds1</DataSourceName>
> <CommandType>Text</CommandType>
> <CommandText>SELECT DISTINCT CustomerID FROM Orders
> WHERE EmployeeID = @.EmployeeIDParam ORDER BY CustomerID ASC</CommandText>
> <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> <QueryParameters>
> <QueryParameter Name="@.EmployeeIDParam">
> <Value>=Parameters!EmployeeIDParam.Value</Value>
> </QueryParameter>
> </QueryParameters>
> </Query>
> </DataSet>
> </DataSets>
> <Language>en-US</Language>
> <RightMargin>1in</RightMargin>
> <BottomMargin>1in</BottomMargin>
> <TopMargin>1in</TopMargin>
> <rd:SnapToGrid>true</rd:SnapToGrid>
> <Width>5in</Width>
> <LeftMargin>1in</LeftMargin>
> <ReportParameters>
> <ReportParameter Name="EmployeeID">
> <DataType>Integer</DataType>
> <DefaultValue>
> <Values>
> <Value>1</Value>
> </Values>
> </DefaultValue>
> <ValidValues>
> <DataSetReference>
> <DataSetName>mydataset2</DataSetName>
> <ValueField>EmployeeID</ValueField>
> <LabelField>EmployeeID</LabelField>
> </DataSetReference>
> </ValidValues>
> <Prompt>Employee ID :</Prompt>
> </ReportParameter>
> <ReportParameter Name="EmployeeIDParam">
> <DataType>Integer</DataType>
> <DefaultValue>
> <Values>
> <Value>=Parameters!EmployeeID.Value</Value>
> </Values>
> </DefaultValue>
> <Prompt> </Prompt>
> </ReportParameter>
> <ReportParameter Name="CustomerIDParam">
> <DataType>String</DataType>
> <DefaultValue>
> <Values>
> <Value>VINET</Value>
> </Values>
> </DefaultValue>
> <ValidValues>
> <DataSetReference>
> <DataSetName>mydataset3</DataSetName>
> <ValueField>CustomerID</ValueField>
> <LabelField>CustomerID</LabelField>
> </DataSetReference>
> </ValidValues>
> <Prompt>Customer ID :</Prompt>
> </ReportParameter>
> </ReportParameters>
> </Report>
> --
> | Thread-Topic: Dynamic Parameter
> | thread-index: AcUFhs+wyP3Cs1ONTxSLxYdNcM59XQ==> | X-WBNR-Posting-Host: 70.66.0.254
> | From: "=?Utf-8?B?U0FjYW51Y2s=?=" <SAcanuck@.discussions.microsoft.com>
> | Subject: Dynamic Parameter
> | Date: Fri, 28 Jan 2005 14:15:01 -0800
> | Lines: 12
> | Message-ID: <AE5AB9C9-7340-4ED3-9EC6-3F5DB22834AA@.microsoft.com>
> | MIME-Version: 1.0
> | Content-Type: text/plain;
> | charset="Utf-8"
> | Content-Transfer-Encoding: 7bit
> | X-Newsreader: Microsoft CDO for Windows 2000
> | Content-Class: urn:content-classes:message
> | Importance: normal
> | Priority: normal
> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> | Newsgroups: microsoft.public.sqlserver.reportingsvcs
> | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
> | Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
> | Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.reportingsvcs:41264
> | X-Tomcat-NG: microsoft.public.sqlserver.reportingsvcs
> |
> | My DB has 3 tables Employee, Department, Job
> |
> | I want to create a report with two parameters.
> |
> | Parameter 1 Options: Employee, Department or Job
> |
> | Parameter 2 Options: When user selects Employee from parameter 1, all
> | employee names will be made available to select in parameter 2, When
> user
> | selects department from parameter 1, all department names will be made
> | available to select in parameter 2.
> |
> | How would one doe this? Any help is appreciated.
> |
>|||Please describe your exact requirement. Becouse your sample is to solve with
the description in the online docu. Isn't it?
"SAcanuck" wrote:
> I had a look at the reporting services books online and it had a description
> on how to use a basiv dynamic parameter...my requirement is a bit more
> advanced than the given example.
> "Dev Main" wrote:
> > It is not necessary to dive into this RDL code.
> >
> > Go to the online help from Reporting Services. There is a chapter Create
> > Report (or similare) and there is a description of using Parameters. On the
> > end of this article is your question answered in the best way.
> >
> >
> >
> > ""Brad Syputa - MS"" wrote:
> >
> > > I did this for a Northwind DB. Here is how my RDL looked. Multiple queries
> > > and data sets returned.
> > >
> > > I changed the names of my data source and data sets. It should still work
> > > against a Northwind DB.
> > >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <Report
> > > xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini
> > > tion"
> > > xmlns:rd="">http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
> > > <DataSources>
> > > <DataSource Name="ds1">
> > >
> > > <rd:DataSourceID>2122d420-3823-467b-8d49-89744c792684</rd:DataSourceID>
> > > <ConnectionProperties>
> > > <DataProvider>SQL</DataProvider>
> > > <ConnectString>data source=servername;initial
> > > catalog=Northwind</ConnectString>
> > > </ConnectionProperties>
> > > </DataSource>
> > > </DataSources>
> > > <rd:ReportID>48c77212-85fb-46c9-9347-e0ecf74aa394</rd:ReportID>
> > > <Body>
> > > <ReportItems>
> > > <Textbox Name="textbox_2">
> > > <Style>
> > > <BackgroundColor>Yellow</BackgroundColor>
> > > <TextAlign>Left</TextAlign>
> > > <FontSize>9pt</FontSize>
> > > </Style>
> > > <Height>.5 in</Height>
> > > <Width>3 in</Width>
> > > <CanGrow>true</CanGrow>
> > > <Value>=Fields!TestResult.Value
> > > + "********Parameters CustomerIDParam Value: " +
> > > Parameters!CustomerIDParam.Value
> > > + "********Parameters EmployeeIDParam Value: " +
> > > Str(Parameters!EmployeeIDParam.Value)
> > > </Value>
> > > <Top>.5 in</Top>
> > > <Left>0 in</Left>
> > > </Textbox>
> > > <Textbox Name="textbox_1">
> > > <Style>
> > > <BackgroundColor>Red</BackgroundColor>
> > > <FontSize>14pt</FontSize>
> > > </Style>
> > > <Height>.5 in</Height>
> > > <Width>3 in</Width>
> > > <CanGrow>true</CanGrow>
> > > <Value>Test Result Below:</Value>
> > > <Top>0 in</Top>
> > > <Left>0 in</Left>
> > > </Textbox>
> > > </ReportItems>
> > > <Height>1.705in</Height>
> > > </Body>
> > > <rd:DrawGrid>true</rd:DrawGrid>
> > > <DataSets>
> > > <DataSet Name="mydataset">
> > > <Fields>
> > > <Field Name="TestResult">
> > > <DataField>TestResult</DataField>
> > > <rd:TypeName>System.String</rd:TypeName>
> > > </Field>
> > > <Field Name="CustomerID">
> > > <DataField>CustomerID</DataField>
> > > <rd:TypeName>System.String</rd:TypeName>
> > > </Field>
> > > <Field Name="EmployeeID">
> > > <DataField>EmployeeID</DataField>
> > > <rd:TypeName>System.Int32</rd:TypeName>
> > > </Field>
> > > </Fields>
> > > <Query>
> > > <DataSourceName>ds1</DataSourceName>
> > > <CommandType>Text</CommandType>
> > > <CommandText>SELECT * , 'Test Passed' as "TestResult" FROM Orders
> > > WHERE EmployeeID = @.EmployeeIDParam AND CustomerID => > > @.CustomerIDParam</CommandText>
> > > <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> > > <QueryParameters>
> > > <QueryParameter Name="@.EmployeeIDParam">
> > > <Value>=Parameters!EmployeeIDParam.Value</Value>
> > > </QueryParameter>
> > > <QueryParameter Name="@.CustomerIDParam">
> > > <Value>=Parameters!CustomerIDParam.Value</Value>
> > > </QueryParameter>
> > > </QueryParameters>
> > > </Query>
> > > </DataSet>
> > > <DataSet Name="mydataset2">
> > > <Fields>
> > > <Field Name="EmployeeID">
> > > <DataField>EmployeeID</DataField>
> > > <rd:TypeName>System.Int32</rd:TypeName>
> > > </Field>
> > > </Fields>
> > > <Query>
> > > <DataSourceName>ds1</DataSourceName>
> > > <CommandType>Text</CommandType>
> > > <CommandText>SELECT DISTINCT EmployeeID FROM Employees
> > > ORDER BY EmployeeID ASC</CommandText>
> > > <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> > > </Query>
> > > </DataSet>
> > > <DataSet Name="mydataset3">
> > > <Fields>
> > > <Field Name="CustomerID">
> > > <DataField>CustomerID</DataField>
> > > <rd:TypeName>System.String</rd:TypeName>
> > > </Field>
> > > </Fields>
> > > <Query>
> > > <DataSourceName>ds1</DataSourceName>
> > > <CommandType>Text</CommandType>
> > > <CommandText>SELECT DISTINCT CustomerID FROM Orders
> > > WHERE EmployeeID = @.EmployeeIDParam ORDER BY CustomerID ASC</CommandText>
> > > <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> > > <QueryParameters>
> > > <QueryParameter Name="@.EmployeeIDParam">
> > > <Value>=Parameters!EmployeeIDParam.Value</Value>
> > > </QueryParameter>
> > > </QueryParameters>
> > > </Query>
> > > </DataSet>
> > > </DataSets>
> > > <Language>en-US</Language>
> > > <RightMargin>1in</RightMargin>
> > > <BottomMargin>1in</BottomMargin>
> > > <TopMargin>1in</TopMargin>
> > > <rd:SnapToGrid>true</rd:SnapToGrid>
> > > <Width>5in</Width>
> > > <LeftMargin>1in</LeftMargin>
> > > <ReportParameters>
> > > <ReportParameter Name="EmployeeID">
> > > <DataType>Integer</DataType>
> > > <DefaultValue>
> > > <Values>
> > > <Value>1</Value>
> > > </Values>
> > > </DefaultValue>
> > > <ValidValues>
> > > <DataSetReference>
> > > <DataSetName>mydataset2</DataSetName>
> > > <ValueField>EmployeeID</ValueField>
> > > <LabelField>EmployeeID</LabelField>
> > > </DataSetReference>
> > > </ValidValues>
> > > <Prompt>Employee ID :</Prompt>
> > > </ReportParameter>
> > > <ReportParameter Name="EmployeeIDParam">
> > > <DataType>Integer</DataType>
> > > <DefaultValue>
> > > <Values>
> > > <Value>=Parameters!EmployeeID.Value</Value>
> > > </Values>
> > > </DefaultValue>
> > > <Prompt> </Prompt>
> > > </ReportParameter>
> > > <ReportParameter Name="CustomerIDParam">
> > > <DataType>String</DataType>
> > > <DefaultValue>
> > > <Values>
> > > <Value>VINET</Value>
> > > </Values>
> > > </DefaultValue>
> > > <ValidValues>
> > > <DataSetReference>
> > > <DataSetName>mydataset3</DataSetName>
> > > <ValueField>CustomerID</ValueField>
> > > <LabelField>CustomerID</LabelField>
> > > </DataSetReference>
> > > </ValidValues>
> > > <Prompt>Customer ID :</Prompt>
> > > </ReportParameter>
> > > </ReportParameters>
> > > </Report>
> > > --
> > > | Thread-Topic: Dynamic Parameter
> > > | thread-index: AcUFhs+wyP3Cs1ONTxSLxYdNcM59XQ==> > > | X-WBNR-Posting-Host: 70.66.0.254
> > > | From: "=?Utf-8?B?U0FjYW51Y2s=?=" <SAcanuck@.discussions.microsoft.com>
> > > | Subject: Dynamic Parameter
> > > | Date: Fri, 28 Jan 2005 14:15:01 -0800
> > > | Lines: 12
> > > | Message-ID: <AE5AB9C9-7340-4ED3-9EC6-3F5DB22834AA@.microsoft.com>
> > > | MIME-Version: 1.0
> > > | Content-Type: text/plain;
> > > | charset="Utf-8"
> > > | Content-Transfer-Encoding: 7bit
> > > | X-Newsreader: Microsoft CDO for Windows 2000
> > > | Content-Class: urn:content-classes:message
> > > | Importance: normal
> > > | Priority: normal
> > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> > > | Newsgroups: microsoft.public.sqlserver.reportingsvcs
> > > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
> > > | Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
> > > | Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.reportingsvcs:41264
> > > | X-Tomcat-NG: microsoft.public.sqlserver.reportingsvcs
> > > |
> > > | My DB has 3 tables Employee, Department, Job
> > > |
> > > | I want to create a report with two parameters.
> > > |
> > > | Parameter 1 Options: Employee, Department or Job
> > > |
> > > | Parameter 2 Options: When user selects Employee from parameter 1, all
> > > | employee names will be made available to select in parameter 2, When
> > > user
> > > | selects department from parameter 1, all department names will be made
> > > | available to select in parameter 2.
> > > |
> > > | How would one doe this? Any help is appreciated.
> > > |
> > >
> > >

Dynamic ORDER BY within stored procedure

I am trying to do something similar to the following where I want to perform dynamic ordering on two tables that have been unioned as shown below.


CREATE PROCEDURE procedure_name
@.regNum varchar(14),
@.sortOrder tinyint = 1
AS
SELECT Filler_OrdNum As 'Accession', RTrim(Obs_Code) As 'Observation', REG As 'Register',
Obs_Date As 'Observation Date'
FROM tblSPG_Header
WHERE
REG = @.regNum
UNION
SELECT Filler_OrdNum As 'Accession', RTrim(Obs_Code) As 'Observation', REG As 'Register',
Obs_Date As 'Observation Date'
FROM tblRCH_Header
WHERE
REG = @.regNum
ORDER BY Obs_Date DESC
GO

Note that I am only sorting on the Obs_Date column, but I'd like to be able to sort on any column within the selection list. I know that I need to use:


ORDER BY CASE WHEN @.sortOrder = 1 THEN Obs_Date END DESC

but I frequently get the following error when I try to do so:

"ORDER BY items must appear in the select list if the statements contain a UNION operator"

If anyone can offer any suggestions, I would appreciate it. Thanks.try something like :


EXEC ( ' SELECT Filler_OrdNum As ''Accession'', RTrim(Obs_Code) As ''Observation'', REG As ''Register'',Obs_Date As ''Observation Date''
FROM tblSPG_Header WHERE REG = ' + @.regNum + ' order by ' + @.ordcolumn +
' UNION
SELECT Filler_OrdNum As ''Accession'', RTrim(Obs_Code) As ''Observation'', REG As ''Register'',
Obs_Date As ''Observation Date'' FROM tblRCH_Header WHERE REG = ' + @.regNum + ' order by ' + @.ordcolumn )

hth

Monday, March 19, 2012

Dynamic layout & whitespace

Hi,

I have a report that, among other things, contains 3 tables laid out side-by-side horizontally. The first table is conditionally visible and when it is hidden the report contains whitespace instead of the table. The problem is that this causes an unappealing visual look because the other 2 tables look shifted too much to the right.

What is the recommended way for dealing with situations like this? There doesn't seem to be support for specifying the location (i.e. top, left) of elements based on expressions. Am I "stuck" with having to create multiple flavors of the report?

Thanks,

Vitaly

Any help is appreciated! :)

Thanks,

Vitaly

|||

Can someone from the SSRS team please shed some light on this?

Thanks

dynamic join based on column value?

Hi,

I have three tables.

The "Master table has a recordid, a masterID, a "IsSubField" and other stuff.

I need to do a join to a second table based on the MasterID...

However for each record, if the "IsSubField" has a True value then it has to use table A to JOIN to, where as if it's False, then it uses table B.

Make sense?

Anyone got any pointers?

Thanks in advance

James

Something like this might work (untested):

Code Snippet


SELECT
m.Col1,
m.Col2,
a.Col2,
b.Col2
FROM MasterTable m
JOIN TableA a
ON ( m.MasterID = a.MasterID
AND m.IsSubField = 'TRUE'
)
JOIN TableB b
ON ( m.MasterID = b.MasterID
AND m.IsSubField = 'False'
)

|||

I am not sure that I get this; maybe something like this?

--drop table dbo.masterTable
--drop table dbo.TableA
--drop table dbo.tableB
go

create table dbo.masterTable
( MasterID integer,
Col1 integer,
col2 integer,
isSubField varchar(5)
)
go
insert into dbo.masterTable
select 1, 11, 21, 'True' union all
select 2, 12, 22, 'False' union all
select 3, 13, 23, 'True'
go

create table dbo.TableA
( MasterID integer,
Col2 integer
)
go

insert into tableA
select 1, 101 union all
select 2, 102 union all
select 3, 103
go

create table dbo.TableB
( MasterID integer,
Col2 integer
)
go

insert into tableB
select 1, 201 union all
select 2, 202 union all
select 3, 203
go


SELECT
m.MasterId,
m.Col1 as m_col1,
m.Col2 as m_col2,
b.Col2 as [subfield?]
FROM MasterTable m
JOIN
( select masterID,
'True' as isSubField,
Col2
from TableA
union all
select masterId,
'False' as isSubField,
Col2
from TableB
) b
on m.MasterId = b.masterId
and m.isSubfield = b.isSubfield

/*
MasterId m_col1 m_col2 subfield?
-- -- -- --
1 11 21 101
2 12 22 202
3 13 23 103
*/

|||

Hi,

thanks for that - I haven't tested it yet, but the snytax is working.. so just need to get a few test records in now..

|||

Hi,

I have this as my query - but don't get any results:

SELECT m.MaterialID, m.MasterID, a.ProductName, b.MaterialName, m.IsSubMaterial
FROM redrose1.Materials_Listings m INNER JOIN
dbo.Products a ON m.MasterID = a.ProductID AND (m.IsSubMaterial = 'No' OR
m.IsSubMaterial IS NULL) INNER JOIN
redrose1.Materials b ON m.MasterID = b.MaterialID AND m.IsSubMaterial = 'Yes'
WHERE (m.MaterialID = @.MaterialID)

any ideas?

|||

Both JOINs should be LEFT JOIN.

Code Snippet


SET NOCOUNT ON


DECLARE @.MasterTable table
( MasterID integer,
Col1 integer,
col2 integer,
isSubField varchar(5)
)


INSERT INTO @.MasterTable VALUES ( 1, 11, 21, 'True' )
INSERT INTO @.MasterTable VALUES ( 2, 12, 22, 'False' )
INSERT INTO @.MasterTable VALUES ( 3, 13, 23, 'True' )


DECLARE @.TableA table
( MasterID integer,
Col2 integer
)


INSERT INTO @.TableA VALUES ( 1, 101 )
INSERT INTO @.TableA VALUES ( 2, 102 )
INSERT INTO @.TableA VALUES ( 3, 103 )


DECLARE @.TableB table
( MasterID integer,
Col2 integer
)


INSERT INTO @.TableB VALUES ( 1, 201 )
INSERT INTO @.TableB VALUES ( 2, 202 )
INSERT INTO @.TableB VALUES ( 3, 203 )


SELECT
m.Col1,
m.Col2,
a.Col2,
b.Col2
FROM @.MasterTable m
LEFT JOIN @.TableA a
ON ( m.MasterID = a.MasterID
AND m.IsSubField = 'TRUE'
)
LEFT JOIN @.TableB b
ON ( m.MasterID = b.MasterID
AND m.IsSubField = 'False'
)

Col1 Col2 Col2 Col2
-- -- -- --
11 21 101 NULL
12 22 NULL 202
13 23 103 NULL

|||excellent - thanks!!

Sunday, March 11, 2012

Dynamic generation of table name

I have a database that has some of its tables created at run-time, i.e., a table name is computed by a program and then the table is created, and the data - written to it. My program will have no trouble finding those tables but the end users will want to run queries using a DBMS client of their choice. They may simply want us to write them some predefined queries that they can execute in MSQuery to build Excel spreadsheets, or something like that.
My question is: is it possible to put in the FROM clause of a SELECT statement anything other than a string describing the name of a table in the database, and more specifically, a sub-query? Let's say I have a table with a known name that contains two columns, and I want to use the concatenation of the contents of those two columns to build the names of some tables, which will then be used in the FROM clause of another SELECT statement. Is that possible and how can I do that? Thanks in advance!
KamenFor end-users: NO, for Developers you can use dynamic SQL. :shocked:
Maybe for the end-users you could create a synonym for these tables, for example: every time you create a new table, you could drop old synonym and create new pointing to new table. ;)|||Bummer... That's what I thought, looking at the SQL documentation. I guess they can always use some "programmable" client, such as MS Access. Thanks, anyway.
Kamen

Dynamic footer visibility

I have two DataSet and two tables in a report. Almost identical reports (top 5). Both DataSet have a Boolean indicator and I am to append an asterisk to a column in the detail rows if indicator is true. If an asterisk appears, I am to display the footer, that has a comment in it explaining the asterisk.

Public Class AsteriskFootNote

'

' To be used on the Visibility.Hidden attribute

'

Dim _FooterVisiblity As Boolean = True

Public ReadOnly Property FooterVisibility() As Boolean

Get

Return _FooterVisibility

End Get

End Property

'

Function AsteriskIndicator(ByVal strInd As String) As String

If (strInd.ToLower = "true") Then

_FooterVisibility = False

Return "*"

End If

Return ""

End Function

'

End Class

I have instantiated two classes Dollars and Hours. In the detail, call the

=Fields!Descr.Value & Code.Dollar.AsteriskIndicator( Fields!MultiInd.Value )

In the footer visibility, I assign hidden:

=Code.Dollar.FooterVisibility

But it does not work. The tables act as if they assign the Hidden value, then processes the detail rows.

I belieive the problem is that RS processes the outer bands/section of the table prior to the inner bands. This means that the footer of a table is actually processed prior to the detail section. Two possibilties are

Use an invisible table at the beginning of a report to call the asterikindicator function.

or

Instead of embedded code you should be able to construct an expression like =iif(sum(iif(fields!boolfield=True,1,0)),False,True) and put it on the visibility property of the footer row.

|||

phuhn wrote:

But it does not work. The tables act as if they assign the Hidden value, then processes the detail rows.

I'm not sure I understand this last bit. What actually happens?

Have you tested that the function calls actually work?

Try placing the expressions inside a textbox and see if the value returned is as expected.

It's probably just a typo but you say that you instatiated a class calld Dollars, yet your expression referes to Dollar.

|||

Yes, I created a testing report and played around with TextBox's and it does work.

My temporary solution was to remove the Footer and replace the footer with a TextBox and it does work.

Phil

Dynamic footer visibility

I have two DataSet and two tables in a report. Almost identical reports (top 5). Both DataSet have a Boolean indicator and I am to append an asterisk to a column in the detail rows if indicator is true. If an asterisk appears, I am to display the footer, that has a comment in it explaining the asterisk.

Public Class AsteriskFootNote

'

' To be used on the Visibility.Hidden attribute

'

Dim _FooterVisiblity As Boolean = True

Public ReadOnly Property FooterVisibility() As Boolean

Get

Return _FooterVisibility

End Get

End Property

'

Function AsteriskIndicator(ByVal strInd As String) As String

If (strInd.ToLower = "true") Then

_FooterVisibility = False

Return "*"

End If

Return ""

End Function

'

End Class

I have instantiated two classes Dollars and Hours. In the detail, call the

=Fields!Descr.Value & Code.Dollar.AsteriskIndicator( Fields!MultiInd.Value )

In the footer visibility, I assign hidden:

=Code.Dollar.FooterVisibility

But it does not work. The tables act as if they assign the Hidden value, then processes the detail rows.

I belieive the problem is that RS processes the outer bands/section of the table prior to the inner bands. This means that the footer of a table is actually processed prior to the detail section. Two possibilties are

Use an invisible table at the beginning of a report to call the asterikindicator function.

or

Instead of embedded code you should be able to construct an expression like =iif(sum(iif(fields!boolfield=True,1,0)),False,True) and put it on the visibility property of the footer row.

|||

phuhn wrote:

But it does not work. The tables act as if they assign the Hidden value, then processes the detail rows.

I'm not sure I understand this last bit. What actually happens?

Have you tested that the function calls actually work?

Try placing the expressions inside a textbox and see if the value returned is as expected.

It's probably just a typo but you say that you instatiated a class calld Dollars, yet your expression referes to Dollar.

|||

Yes, I created a testing report and played around with TextBox's and it does work.

My temporary solution was to remove the Footer and replace the footer with a TextBox and it does work.

Phil

dynamic filters

i am working on a publication which has about 400 tables. i want to define
dynamic filters, but i dont want to use EM.
how can i add the filters on query analyzer?
Create one publication and subscription using dynamic filters. Script it
out, and edit the script. Drop the publication and use the script to deploy
it to the publisher and all subscribers.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"uncle ho" <uncle ho@.discussions.microsoft.com> wrote in message
news:9B2CF8CE-A90E-4F75-BE32-785283A01432@.microsoft.com...
> i am working on a publication which has about 400 tables. i want to define
> dynamic filters, but i dont want to use EM.
> how can i add the filters on query analyzer?

Friday, March 9, 2012

Dynamic feed of table name to Transfer SQL Server Object Task

Hi
I would like to be able to feed the List of tables to the Transfer SQL Server Object Task dynamically.
I have got a foreachloop container which it feeds the table names into a variable @.table_name (string).

Transfer SQL Server Object Task is with in foreachloop container

I did add an expression into the property of Transfer SQL Server Object Task and assign the tablelist property to @.table_name

I would be grateful if you can give me any hint.
Thanks
S

The logic looks right to me...are you seeing any error?

I have a blog post that explains how to iterate through a SQL result set (in your case to get the list of tables) using a foreach loop conatiner.

I hope that hepls you

|||

Hi,

I have faced this issue where TablesList property of Transfer SQL Server Object task takes in list of tables to transfer. There is no way to dynamically set the property through SSIS variable because this property expects StringCollection object. If you declare an SSIS variable as Object and assign it to TablesList property of the task thru Expression, it will not work because expressions cannot evaluate Object data type

I did a workaround by creating a child package in ScripTask and adding a TransferSQL server object task programmatically and assigning the TableList property as StringCollection object in VB.NET

Thanks

Mohit

|||Thanks Rafael,
I feed the list of tables (as object) to foreach Loop Container and the loop will put them in to a string variable.
I have got other tasks in the foreach Loop Container as well as transfer SQL Server Object tasks and they do use the table name (the string variable with out the problem)
the problem starts when I try to feed this table name to Tablelist properties of transfer SQL Server Object tasks which it complians saying that I it can not assign the string value to the tablelist property.
I have even tried to feed a dataset(object -list of tables ) to that property and even that didn't work.

|||Thanks Mohit for your reply.
so in the child Script task you are populating the table collation the way it should be but how are you feeding it to TabeList Propery.
would you be able to attach the VB code please.
Many Thanks
|||

This is how to do it...

'create sql server object task to move tables

Dim MoveTable As Executable = Child.Executables.Add("STOCK:TransferSqlServerObjectsTask")

Dim MoveTableTask As TaskHost = CType(MoveTable, TaskHost)

'set properties

MoveTableTask.Properties("CopySchema").SetValue(MoveTableTask, True)

MoveTableTask.Properties("CopyData").SetValue(MoveTableTask, True)

'create a stringcollection of tables

Dim Tables As StringCollection = New StringCollection()

Tables.Add('Table1')

Tables.Add('Table2')

Tables.Add('Table3')

'create string collection for tables to transfer

MoveTableTask.Properties("TablesList").SetValue(MoveTableTask, Tables))

'set the source and destination connections

......................

'execute package and dispose

Thanks

Mohit

|||thanks|||I manage to use this method and copy all the tables.
The problem is if I tables belong to a schema this method won't work.
I am using version variable as schema name.
sample
version ="VT.1"
Table_name="Sample"

sc.Add("[" + Version + "]." + Dts.Variables("Table_Name").Value.ToString)

so I am expecting to add [VT.1].sample to the TableList collection.
but when it is trying to populate tablelist property from the sc (collection) variable it complains that table does not exist at source!
which I know for the fact it does

Any ideas?|||

Kolf wrote:

I manage to use this method and copy all the tables.
The problem is if I tables belong to a schema this method won't work.
I am using version variable as schema name.
sample
version ="VT.1"
Table_name="Sample"

sc.Add("[" + Version + "]." + Dts.Variables("Table_Name").Value.ToString)

so I am expecting to add [VT.1].sample to the TableList collection.
but when it is trying to populate tablelist property from the sc (collection) variable it complains that table does not exist at source!
which I know for the fact it does

Any ideas?

Can you try with any table with dbo schema wether you are able to transfer. Also check whether you have permission on the schema to access the table.

Thanks

Mohit

|||it does work with dbo schema
and I do have permission on the schemas
it seems like the object copy task doesn't understand the collection of the table names with the schema.
any solution?
thanks|||

Kolf wrote:

it does work with dbo schema
and I do have permission on the schemas
it seems like the object copy task doesn't understand the collection of the table names with the schema.
any solution?
thanks

It seems it does not understand schemas. Bcoz even creating the Transfer SQL server Object task in design time , I selected one table of schema1. I had same tablename for schema2. When i select one table from schema1 for table list property and close the task and edit again, I see both the tables of different schema selected automatically. Seems there is a problem. Suggest you to use tablename to maintain versions like tablename + "_" + VersionName.

Thanks

Mohit

|||

Thanks for the quick reply.

so it seems like this is a bug as the functionality is there but it doesn't work.

I have to be able to copy tables in a schema to the destination DB

I have even tried to create the schema manually at destination

let's say

I have a table

schema:[Dt.1]

table:test

then I've got [Dt.1].test as my source table

I've created schema [Dt.1] at the destination database but still SQL object copy task complains that task can't see test table in the source database.

this is even the case if I hardcode the name of the tables in the task!

|||

Kolf wrote:

Thanks for the quick reply.

so it seems like this is a bug as the functionality is there but it doesn't work.

I have to be able to copy tables in a schema to the destination DB

I have even tried to create the schema manually at destination

let's say

I have a table

schema:[Dt.1]

table:test

then I've got [Dt.1].test as my source table

I've created schema [Dt.1] at the destination database but still SQL object copy task complains that task can't see test table in the source database.

this is even the case if I hardcode the name of the tables in the task!

Just check in your code for this:

MoveTableTask.Properties("CopySchema").SetValue(MoveTableTask, True) to copy schemas thru Task and

MoveTableTask.Properties("SchemaList").SetValue(MoveTableTask,sc) is assigned list of schemas to transfer .

If does not work and you want to stick to schemas you can try dataflow tasks

Thanks

Mohit

|||Dataflow task can't be used as I have different tables with different table columns
would you be able to create a sample dtsx based on adventureworks please
thanks|||Thanks Mohit
the problem with dataflow tasks is that (my table names are dynamic and I have got a foreach Loop that feed the table names to a dataflow
and in dataflow I have got a
* OLE DB source ( which the data access methode has been set to Variable) and that's how I feed my table name (variable called User::source_table ) and an example value for it will be
[DT.1].TableA
which is pointing to [DT.1] and with in the OLEDB Source I can preview the data

* also I have got an OLE DB Destination which same as OLE DB source is reading the table name from a variable ( which I'm using the same variable name , as the table name and the schema on both servers are the same)

problem: in order for this to work I have to manually click on the column map section in OLEDB Destinaiton section and save the package(manually) as the tables and they columns are changing this method won't be possible.

I hope I 've explained it properly.
Many Thanks

Dynamic feed of table name to Transfer SQL Server Object Task

Hi
I would like to be able to feed the List of tables to the Transfer SQL Server Object Task dynamically.
I have got a foreachloop container which it feeds the table names into a variable @.table_name (string).

Transfer SQL Server Object Task is with in foreachloop container

I did add an expression into the property of Transfer SQL Server Object Task and assign the tablelist property to @.table_name

I would be grateful if you can give me any hint.
Thanks
S

The logic looks right to me...are you seeing any error?

I have a blog post that explains how to iterate through a SQL result set (in your case to get the list of tables) using a foreach loop conatiner.

I hope that hepls you

|||

Hi,

I have faced this issue where TablesList property of Transfer SQL Server Object task takes in list of tables to transfer. There is no way to dynamically set the property through SSIS variable because this property expects StringCollection object. If you declare an SSIS variable as Object and assign it to TablesList property of the task thru Expression, it will not work because expressions cannot evaluate Object data type

I did a workaround by creating a child package in ScripTask and adding a TransferSQL server object task programmatically and assigning the TableList property as StringCollection object in VB.NET

Thanks

Mohit

|||Thanks Rafael,
I feed the list of tables (as object) to foreach Loop Container and the loop will put them in to a string variable.
I have got other tasks in the foreach Loop Container as well as transfer SQL Server Object tasks and they do use the table name (the string variable with out the problem)
the problem starts when I try to feed this table name to Tablelist properties of transfer SQL Server Object tasks which it complians saying that I it can not assign the string value to the tablelist property.
I have even tried to feed a dataset(object -list of tables ) to that property and even that didn't work.

|||Thanks Mohit for your reply.
so in the child Script task you are populating the table collation the way it should be but how are you feeding it to TabeList Propery.
would you be able to attach the VB code please.
Many Thanks
|||

This is how to do it...

'create sql server object task to move tables

Dim MoveTable As Executable = Child.Executables.Add("STOCK:TransferSqlServerObjectsTask")

Dim MoveTableTask As TaskHost = CType(MoveTable, TaskHost)

'set properties

MoveTableTask.Properties("CopySchema").SetValue(MoveTableTask, True)

MoveTableTask.Properties("CopyData").SetValue(MoveTableTask, True)

'create a stringcollection of tables

Dim Tables As StringCollection = New StringCollection()

Tables.Add('Table1')

Tables.Add('Table2')

Tables.Add('Table3')

'create string collection for tables to transfer

MoveTableTask.Properties("TablesList").SetValue(MoveTableTask, Tables))

'set the source and destination connections

......................

'execute package and dispose

Thanks

Mohit

|||thanks|||I manage to use this method and copy all the tables.
The problem is if I tables belong to a schema this method won't work.
I am using version variable as schema name.
sample
version ="VT.1"
Table_name="Sample"

sc.Add("[" + Version + "]." + Dts.Variables("Table_Name").Value.ToString)

so I am expecting to add [VT.1].sample to the TableList collection.
but when it is trying to populate tablelist property from the sc (collection) variable it complains that table does not exist at source!
which I know for the fact it does

Any ideas?|||

Kolf wrote:

I manage to use this method and copy all the tables.
The problem is if I tables belong to a schema this method won't work.
I am using version variable as schema name.
sample
version ="VT.1"
Table_name="Sample"

sc.Add("[" + Version + "]." + Dts.Variables("Table_Name").Value.ToString)

so I am expecting to add [VT.1].sample to the TableList collection.
but when it is trying to populate tablelist property from the sc (collection) variable it complains that table does not exist at source!
which I know for the fact it does

Any ideas?

Can you try with any table with dbo schema wether you are able to transfer. Also check whether you have permission on the schema to access the table.

Thanks

Mohit

|||it does work with dbo schema
and I do have permission on the schemas
it seems like the object copy task doesn't understand the collection of the table names with the schema.
any solution?
thanks|||

Kolf wrote:

it does work with dbo schema
and I do have permission on the schemas
it seems like the object copy task doesn't understand the collection of the table names with the schema.
any solution?
thanks

It seems it does not understand schemas. Bcoz even creating the Transfer SQL server Object task in design time , I selected one table of schema1. I had same tablename for schema2. When i select one table from schema1 for table list property and close the task and edit again, I see both the tables of different schema selected automatically. Seems there is a problem. Suggest you to use tablename to maintain versions like tablename + "_" + VersionName.

Thanks

Mohit

|||

Thanks for the quick reply.

so it seems like this is a bug as the functionality is there but it doesn't work.

I have to be able to copy tables in a schema to the destination DB

I have even tried to create the schema manually at destination

let's say

I have a table

schema:[Dt.1]

table:test

then I've got [Dt.1].test as my source table

I've created schema [Dt.1] at the destination database but still SQL object copy task complains that task can't see test table in the source database.

this is even the case if I hardcode the name of the tables in the task!

|||

Kolf wrote:

Thanks for the quick reply.

so it seems like this is a bug as the functionality is there but it doesn't work.

I have to be able to copy tables in a schema to the destination DB

I have even tried to create the schema manually at destination

let's say

I have a table

schema:[Dt.1]

table:test

then I've got [Dt.1].test as my source table

I've created schema [Dt.1] at the destination database but still SQL object copy task complains that task can't see test table in the source database.

this is even the case if I hardcode the name of the tables in the task!

Just check in your code for this:

MoveTableTask.Properties("CopySchema").SetValue(MoveTableTask, True) to copy schemas thru Task and

MoveTableTask.Properties("SchemaList").SetValue(MoveTableTask,sc) is assigned list of schemas to transfer .

If does not work and you want to stick to schemas you can try dataflow tasks

Thanks

Mohit

|||Dataflow task can't be used as I have different tables with different table columns
would you be able to create a sample dtsx based on adventureworks please
thanks|||Thanks Mohit
the problem with dataflow tasks is that (my table names are dynamic and I have got a foreach Loop that feed the table names to a dataflow
and in dataflow I have got a
* OLE DB source ( which the data access methode has been set to Variable) and that's how I feed my table name (variable called User::source_table ) and an example value for it will be
[DT.1].TableA
which is pointing to [DT.1] and with in the OLEDB Source I can preview the data

* also I have got an OLE DB Destination which same as OLE DB source is reading the table name from a variable ( which I'm using the same variable name , as the table name and the schema on both servers are the same)

problem: in order for this to work I have to manually click on the column map section in OLEDB Destinaiton section and save the package(manually) as the tables and they columns are changing this method won't be possible.

I hope I 've explained it properly.
Many Thanks

Wednesday, March 7, 2012

Dynamic database tables

How does one make a database table dynamic?
I need to have a single report display data from different SQL tables
depending on which client is viewing the data.Here's an example:
1. Run the following static SQL in data pane of report designer: select
name, xtype, crdate from sysobjects
2. Switch to Layout view. This creates the fields in fields window.
3. Go back to the data pane and pase the following query into it: ="select
name, xtype, crdate from " & iif(LCase(User!UserID) = "redmond\ravimu",
"pubs", "northwind") & "..sysobjects where type = 'u'". This will
dynamically source the data from diferent table depending on the current
user.
Notes:
1. Assumption: Table schemas are the same.
2. If the target tables have same number of columna but different names, you
can map each column name to a unique alias as follows: select name As Col1,
xtype As Col2, crdate As Col3 from sysobjects
3. If you have many users, you may want to replace iif() with Switch()
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html
/vafctswitch.asp)
--
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"jimmy stewart" <jims@.wolfmagick.com> wrote in message
news:u9$uYmQbEHA.3944@.tk2msftngp13.phx.gbl...
> How does one make a database table dynamic?
> I need to have a single report display data from different SQL tables
> depending on which client is viewing the data.
>

Sunday, February 26, 2012

Dynamic create table, create index based upon a given database

Can I dynamically (from a stored procedure) generate
a create table script of all tables in a given database (with defaults etc)
a create view script of all views
a create function script of all functions
a create index script of all indexes.
(The result will be 4 scripts)

Arno de Jong,
The Netherlands.The following will create a script for each type of object:

EXEC XP_CMDSHELL '"C:\Program Files\Microsoft SQL
Server\MSSQL\Upgrade\SCPTXFR" /I /D DATABASE_NAME /S SERVER_NAME /F
C:\PATH_NAME'

--
David Portas
----
Please reply only to the newsgroup
--

"A.M. de Jong" <arnojo@.wxs.nl> wrote in message
news:bpkpq8$7vi$1@.reader10.wxs.nl...
> Can I dynamically (from a stored procedure) generate
> a create table script of all tables in a given database (with defaults
etc)
> a create view script of all views
> a create function script of all functions
> a create index script of all indexes.
> (The result will be 4 scripts)
> Arno de Jong,
> The Netherlands.

Friday, February 24, 2012

Dynamic connect...?

I am trying to implement a web application user login system where every user is an Oracle user, so I can avoid having tables containing passwords and what not. In fact, having passwords in a table is not an option, even if they're encrypted. Anyway, I'm trying to set it up so that the login page is under a DAD that logs in as a user with rights to the login package only. Then, once the user has typed in their name and password and submitted, I want to then log them in as their user that has already been created in Oracle.

The first part is easy enough, but I have tried unsuccessfully to find some way to use dynamic sql to change users, such as EXECUTE IMMEDIATE 'CONNECT user/pass@.db'; and concatenating the appropriate values, but nothing seems to work.

I'm trying to avoid the basic authentication dialog box, as well as avoiding storing passwords in tables. I have looked into the custom authorization stuff provided by owa_custom, but I can't see any way to implement it with Oracle users. Any help on this would be greatly appreciated. Thanks!"connect" is a SQL*Plus command and hence cannot be executed dynamically. Other examples would be "show user", "desc table" etc. Only sql commands can be executed using dynamic sql.

But if you have the uid & pwd, can you not connect from your web application to see if the user is a valid database user or not ?|||Yeah, that is an option. I'm trying to avoid using JDBC or anything like that. However, if need be, I suppose that is something I can try. If there are any other ways to connect from the app, I would be interested in hearing about them. My experience with web application login systems is extremely limited, so any kind of help is greatly appreciated.

Sunday, February 19, 2012

Dynamic Columns in Report

I have two tables with structure something like
User Attributes
AttributeID
AttributeName
Description
IsRequired
ChoiceArray
OptionType
DefaultValue
MaxVal
MinVal
Mask
DecimalPlaces
isMultiLine
DateFormat
CompanyID
UDFTypeID
EntityID
isVisible
Values of the tables can be
User notes
Published comments
Reject reasons
Whereas transaction Entity can be some other entity like purchase order, etc
and this information will saved for particular record as per customersâ'
needs. There can be thousand of customer with their own fields ranging from
0-20. The values of these user defined fields are stored in another tables
with relationship to user defined field and business transactionID. For
example for purchase orders values tables would be
UDFValueID
POID
Value
AttributeID
Values of the tales can be
1 1 Some Values 1
2 1 Some Values 2
3 1 Some Values 3
I need to develop a report that could be able to display the information in
format like
User notes Published comments Reject reasons etc. etc.
Some Values some value some reasons
I know that using pivot I can show the rows in columns, but I really donâ't
know how I can do that same with reporting services.
My question is how I can create/Add columns in reports on runtime or
dynamically. As per above requirement.A matrix table will allow dynamic columns.
"nettellect" wrote:
> I have two tables with structure something like
>
> User Attributes
> AttributeID
> AttributeName
> Description
> IsRequired
> ChoiceArray
> OptionType
> DefaultValue
> MaxVal
> MinVal
> Mask
> DecimalPlaces
> isMultiLine
> DateFormat
> CompanyID
> UDFTypeID
> EntityID
> isVisible
> Values of the tables can be
> User notes
> Published comments
> Reject reasons
> Whereas transaction Entity can be some other entity like purchase order, etc
> and this information will saved for particular record as per customersâ'
> needs. There can be thousand of customer with their own fields ranging from
> 0-20. The values of these user defined fields are stored in another tables
> with relationship to user defined field and business transactionID. For
> example for purchase orders values tables would be
> UDFValueID
> POID
> Value
> AttributeID
> Values of the tales can be
> 1 1 Some Values 1
> 2 1 Some Values 2
> 3 1 Some Values 3
> I need to develop a report that could be able to display the information in
> format like
> User notes Published comments Reject reasons etc. etc.
> Some Values some value some reasons
> I know that using pivot I can show the rows in columns, but I really donâ't
> know how I can do that same with reporting services.
> My question is how I can create/Add columns in reports on runtime or
> dynamically. As per above requirement.
>|||is there any sample or wlkthrough that could help me in developing this
"Jimbo" wrote:
> A matrix table will allow dynamic columns.
>
>
> "nettellect" wrote:
> > I have two tables with structure something like
> >
> >
> > User Attributes
> >
> > AttributeID
> > AttributeName
> > Description
> > IsRequired
> > ChoiceArray
> > OptionType
> > DefaultValue
> > MaxVal
> > MinVal
> > Mask
> > DecimalPlaces
> > isMultiLine
> > DateFormat
> > CompanyID
> > UDFTypeID
> > EntityID
> > isVisible
> >
> > Values of the tables can be
> >
> > User notes
> > Published comments
> > Reject reasons
> >
> > Whereas transaction Entity can be some other entity like purchase order, etc
> > and this information will saved for particular record as per customersâ'
> > needs. There can be thousand of customer with their own fields ranging from
> > 0-20. The values of these user defined fields are stored in another tables
> > with relationship to user defined field and business transactionID. For
> > example for purchase orders values tables would be
> >
> > UDFValueID
> > POID
> > Value
> > AttributeID
> >
> > Values of the tales can be
> > 1 1 Some Values 1
> > 2 1 Some Values 2
> > 3 1 Some Values 3
> >
> > I need to develop a report that could be able to display the information in
> > format like
> >
> > User notes Published comments Reject reasons etc. etc.
> > Some Values some value some reasons
> >
> > I know that using pivot I can show the rows in columns, but I really donâ't
> > know how I can do that same with reporting services.
> >
> > My question is how I can create/Add columns in reports on runtime or
> > dynamically. As per above requirement.
> >|||Design a dataset with a structure like:
RowValue
ColumnValue
CellValue
Create the matrix table and place those fields in the appropraite sections.
The matrix table will create columns to the number of unique column values
The matrix table will create rows to the number of unique row values
The intersection of row/column will be populated with your cell value
(usually a sum(cellvalue) )
If this doesn't help ask the google god.
"nettellect" wrote:
> is there any sample or wlkthrough that could help me in developing this
> "Jimbo" wrote:
> > A matrix table will allow dynamic columns.
> >
> >
> >
> >
> >
> > "nettellect" wrote:
> >
> > > I have two tables with structure something like
> > >
> > >
> > > User Attributes
> > >
> > > AttributeID
> > > AttributeName
> > > Description
> > > IsRequired
> > > ChoiceArray
> > > OptionType
> > > DefaultValue
> > > MaxVal
> > > MinVal
> > > Mask
> > > DecimalPlaces
> > > isMultiLine
> > > DateFormat
> > > CompanyID
> > > UDFTypeID
> > > EntityID
> > > isVisible
> > >
> > > Values of the tables can be
> > >
> > > User notes
> > > Published comments
> > > Reject reasons
> > >
> > > Whereas transaction Entity can be some other entity like purchase order, etc
> > > and this information will saved for particular record as per customersâ'
> > > needs. There can be thousand of customer with their own fields ranging from
> > > 0-20. The values of these user defined fields are stored in another tables
> > > with relationship to user defined field and business transactionID. For
> > > example for purchase orders values tables would be
> > >
> > > UDFValueID
> > > POID
> > > Value
> > > AttributeID
> > >
> > > Values of the tales can be
> > > 1 1 Some Values 1
> > > 2 1 Some Values 2
> > > 3 1 Some Values 3
> > >
> > > I need to develop a report that could be able to display the information in
> > > format like
> > >
> > > User notes Published comments Reject reasons etc. etc.
> > > Some Values some value some reasons
> > >
> > > I know that using pivot I can show the rows in columns, but I really donâ't
> > > know how I can do that same with reporting services.
> > >
> > > My question is how I can create/Add columns in reports on runtime or
> > > dynamically. As per above requirement.
> > >