Showing posts with label parameter. Show all posts
Showing posts with label parameter. Show all posts

Thursday, March 29, 2012

Create table, table name as procedure parameter ?

Hi,

Is it possible to create a table in a stored procedure, where the table name

comes as a string procedure parameter?

Sorry, I am a newbie, maybe it is not possible this way,

but then what is the suggested way?

this results error in SQL Management Studio, if I press Parse.

>Incorrect syntax near '@.tableName'.

the "CREATE TABLE MyFixNameTable" line works, but it fixes the table name.

Code Snippet

CREATE PROCEDURE CreateMyTable

-- Add the parameters for the stored procedure here

@.tableName nvarchar(MAX) = ''

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;

SET ANSI_NULLS ON

SET QUOTED_IDENTIFIER ON

-- CREATE TABLE MyFixNameTable

CREATE TABLE @.tableName

(

"^First Name" varchar(25) NOT NULL,

"^Last Name" varchar(25) NOT NULL

)

END

You can't supply an object name as a variable/parameter to a SQL statement.

However, you could create the entire SQL statement as a string, and then use sp_executesql to execute that string.

You may find this article useful:


Dynamic SQL -
The Curse and Blessings of Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html

|||

Like Arnie saie, you cannot create a table like this. Generally speaking, it is rarely a good thing to be programatically creating permanent tables to start with. You can do this with dynamic sql, but why? If you are going to load the data with the results of a query, it is likely best for you to do something like:


select firstName, lastName
into yourTableName
from ...

It is usually faster and avoids some logging overhead. The best way to do this is usually to have a permanent table that includes some other column to denote when you searched for data, etc, some discriminator. Then you can work with the data in the same tables every time you do this, and you code is simplified, and the data is available more readily for reporting what is being done.

Monday, March 19, 2012

Create report items dynamically - how?

Hi, All,
I have a report with a parameter (a combo box with two names), that only
show the CompanyName on the report. When I choose Name No1, I would like to
show 4 textboxes, and choosing the name No2, I would like to show another
one, and hide the pevious four.
I'm going to make these textboxes dynamically.
Can I do it? Or is there another solution?
Thanks,
SzabtiYou can write an Expression in the "Hidden" part of the "Visibility" property
of the fields involved. Let this expression evaluate your parameter and have
it return a boolean value. That's all!
D.P.
"szabti" wrote:
> Hi, All,
> I have a report with a parameter (a combo box with two names), that only
> show the CompanyName on the report. When I choose Name No1, I would like to
> show 4 textboxes, and choosing the name No2, I would like to show another
> one, and hide the pevious four.
> I'm going to make these textboxes dynamically.
> Can I do it? Or is there another solution?
> Thanks,
> Szabti
>
>|||Yes, I've done it at first. But here was a great problem with rendering:
after hiding the first 4 elements and showing the only one, remaining part
of my report (these are textboxes with summary data) was fall apart: some
textboxes moved to top of another and the value became unreadable.
So it is why I've thought to draw these elements dynamically...
szabti
"D.P." <DP@.discussions.microsoft.com> az alábbiakat írta a következõ
hírüzenetben: 896D6245-F152-49CD-9B38-7AFDF961C7C5@.microsoft.com...
> You can write an Expression in the "Hidden" part of the "Visibility"
> property
> of the fields involved. Let this expression evaluate your parameter and
> have
> it return a boolean value. That's all!
> D.P.
> "szabti" wrote:
>> Hi, All,
>> I have a report with a parameter (a combo box with two names), that only
>> show the CompanyName on the report. When I choose Name No1, I would like
>> to
>> show 4 textboxes, and choosing the name No2, I would like to show another
>> one, and hide the pevious four.
>> I'm going to make these textboxes dynamically.
>> Can I do it? Or is there another solution?
>> Thanks,
>> Szabti
>>
>>

Sunday, March 11, 2012

Create Procedure Command

Good morning,
The Transact-SQL Reference documentation states:
"All data types, including text, ntext and image, can be used as a parameter
for a stored procedure."
I would like to pass a table variable... is this possible?
Thanks,
FOrch>I would like to pass a table variable... is this possible?
NO
--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Forch" <Forch@.discussions.microsoft.com> wrote in message
news:1AAA1E85-4F2D-4110-A6D0-81DDE4255694@.microsoft.com...
> Good morning,
> The Transact-SQL Reference documentation states:
> "All data types, including text, ntext and image, can be used as a
> parameter
> for a stored procedure."
> I would like to pass a table variable... is this possible?
> Thanks,
> FOrch
>

Create Proc Parameter Issue

Hi All,
I have created a stored proc that is set to accept @.username =
varchar(40)...it fails when the username is FULLY qualified with Domain name
...ex: 'MyDomain\Username'...how do I get my procedure to except this FULL
name?
Thanks...M.Please post some sample code on how you execute that.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Michelle" <smiley2211@.yahoo.com> schrieb im Newsbeitrag
news:eVrMaXrZFHA.3220@.TK2MSFTNGP14.phx.gbl...
> Hi All,
> I have created a stored proc that is set to accept @.username =
> varchar(40)...it fails when the username is FULLY qualified with Domain
> name ...ex: 'MyDomain\Username'...how do I get my procedure to except this
> FULL name?
> Thanks...M.
>|||The datatype for usernames in SQL (as used in the system tables) is sysname,
which is equivalent to nvarchar(128). Use that instead of varchar(40).
Jacco Schalkwijk
SQL Server MVP
"Michelle" <smiley2211@.yahoo.com> wrote in message
news:eVrMaXrZFHA.3220@.TK2MSFTNGP14.phx.gbl...
> Hi All,
> I have created a stored proc that is set to accept @.username =
> varchar(40)...it fails when the username is FULLY qualified with Domain
> name ...ex: 'MyDomain\Username'...how do I get my procedure to except this
> FULL name?
> Thanks...M.
>|||Yes, I tried sysname as well...still errors: "Associated statement is not
prepared"
************snippet********
CREATE PROCEDURE sp_getprivs (@.username sysname = null) AS
set nocount on
declare @.dbn varchar(30)
declare test cursor for
select name from master..sysdatabases
etc....
*****************
"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid> wrote
in message news:%23$f5sirZFHA.3780@.tk2msftngp13.phx.gbl...
> The datatype for usernames in SQL (as used in the system tables) is
> sysname, which is equivalent to nvarchar(128). Use that instead of
> varchar(40).
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Michelle" <smiley2211@.yahoo.com> wrote in message
> news:eVrMaXrZFHA.3220@.TK2MSFTNGP14.phx.gbl...
>|||Sorry...I execute this as such...
sp_getprivs 'MyDomain\Username'
Thanks...M
"Michelle" <smiley2211@.yahoo.com> wrote in message
news:ukE3YorZFHA.2496@.TK2MSFTNGP14.phx.gbl...
> Yes, I tried sysname as well...still errors: "Associated statement is not
> prepared"
> ************snippet********
> CREATE PROCEDURE sp_getprivs (@.username sysname = null) AS
> set nocount on
> declare @.dbn varchar(30)
> declare test cursor for
> select name from master..sysdatabases
> etc....
> *****************
>
> "Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid>
> wrote in message news:%23$f5sirZFHA.3780@.tk2msftngp13.phx.gbl...
>|||Try using delimiters:
sp_getprivs '[MyDomain\Username]'
Jacco Schalkwijk
SQL Server MVP
"Michelle" <smiley2211@.yahoo.com> wrote in message
news:OhhR1qrZFHA.2412@.TK2MSFTNGP10.phx.gbl...
> Sorry...I execute this as such...
> sp_getprivs 'MyDomain\Username'
> Thanks...M
> "Michelle" <smiley2211@.yahoo.com> wrote in message
> news:ukE3YorZFHA.2496@.TK2MSFTNGP14.phx.gbl...
>|||Thanks, that worked...
...M
"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid> wrote
in message news:ui3WLisZFHA.2884@.tk2msftngp13.phx.gbl...
> Try using delimiters:
> sp_getprivs '[MyDomain\Username]'
>
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Michelle" <smiley2211@.yahoo.com> wrote in message
> news:OhhR1qrZFHA.2412@.TK2MSFTNGP10.phx.gbl...
>

Friday, February 24, 2012

Create Global Variable like VB... can it be done?

I just want to store the value of a parameter in a global variable that all my reports in the same project can use.

My goal is to create a dynamic query. For example:

Company Name: Widgets inc.

Divisions: Sales, Service, Tech, Accounting

I have a matrix and when I click on the more information button it goes to another report. I want the next report to know what division is currently selected in the dropdown parameter. So, being a VB programmer, I thought I could store parameter1.division.value into a global variable and update the variable whenever the parameter changes.

This way, on the next report, my query's where statement is the global variable.

@.GlobalVariable = parameter1.division.value

Select name, address, phone FROM Employee WHERE division = @.GlobalVariable

I am using Visual Studio to design this project although I would prefer to use VB or ASP. But this is my only stumbling block right now. Everything else is complete.

Please let me know if anyone can help.

Thanks.

John

There is not a concept of a global variable for multiple reports that I know of.

You could potentially do something with a table that could store the global value by user id & identifier, and retrieve the variable from the table. Or you could setup a web service to get/set the variable.

You may be able to add a reference to a DLL in every report, and share between them, though I woud think it would be destroyed after the report session times out.

http://www.codeproject.com/dll/data_seg_share.asp

cheers,

Andrew

|||

Looks like you need a report parameter. You don't need to show it to the user, but just default it.

Create Extended Procedures in VS 2005

Hi

I am trying to write an extended procedure that accepts a string parameter and returns an integer value. The extended procedure calls a regular stored procedure of a database passing the string parameter as an input. The int value is an OUT parameter to this procedure.

Can I some one suggest where do I get started with respect to this in VS 2005.Why do you want to write an extended stored procedure to call a TSQL SP? This is overkill actually. Extended SPs are meant for computation intensive operations or other logic that cannot be performed efficiently using TSQL. It has it's limitations, performance, reliability and security issues. Or you trying to just learn extended SP programming? If later you can look at the SQL Server samples. You can also look at ODBC/OLEDB samples that will show you how to call SPs.|||The thing is that we need to make DML changes while calling a function. Since normal UDFs dont allow to do it I am trying to call an xp. Since we also need to look at concurrency I am having a stored procedure with transactions taken care. Hence the need of calling T_SQL sp from xp.|||Where do I look for the Extended Stored Procedure DLL Wizard while I open VS 2005 --> Open Project.

I do not see any such wizrd name.

Regards
Imtiaz|||

Use of side-effecting code from UDF is not recommended. It takes lot of work to get it right (dealing with bound connections, concurrency issues, deadlocks, scalability of xps, virtual memory issues depending on how the xp is written etc). Lastly, use of such UDFs in SELECT statement can cause unexpected behavior.

Sunday, February 19, 2012

Create Dynamic Query based on Report Parameter

I have one Report parameter "Query1". I want to create Dynamic Query, How can I do this?

ex. If I select Station in Query1 parameter then report should generate by Station Dimenstion attribute

[Dim Station].[Station Name].[Station Name].ALLMEMBERS

If I select Free Test in Query1 parameter then report should generate by Free Test Dimension attribute

[Dim Free Test].[Free Test].[Free Test].ALLMEMBERS

My existin query is below:

SELECT NON EMPTY ([Measures].[Total Test Count]) ON COLUMNS,

NON EMPTY STRTOSET(@.Query1) * [Dim OverallResult].[Overall Result].[Overall Result] ON ROWS

FROM [OLAP Test Cube]

Report Parameter Name: Query1

Available Non Queried value in Report Parameter is below:

Lable Value

Station [Dim Station].[Station Name].[Station Name]

Free Test [Dim Free Test].[Free Test].[Free Test]

Default Value is below:

Non-Queried value: [Dim Free Test].[Free Test].[Free Test]

I want to Change Column Alias also through Select MDX Query.

let me know if anybody know this?

anyone know about this?|||

This http://www.databasejournal.com/features/mssql/article.php/10894_3504651 article should give you an idea how to use parameters building MDX queries in Reporting Services.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

this is not working for me. any other solution?

in this example they added Dimension member in filter area. I need different dimension in filter area.

Create Dynamic Query based on Report Parameter

I have one Report parameter "Query1". I want to create Dynamic Query, How can I do this?

ex. If I select Station in Query1 parameter then report should generate by Station Dimenstion attribute

[Dim Station].[Station Name].[Station Name].ALLMEMBERS

If I select Free Test in Query1 parameter then report should generate by Free Test Dimension attribute

[Dim Free Test].[Free Test].[Free Test].ALLMEMBERS

My existin query is below:

SELECT NON EMPTY ([Measures].[Total Test Count]) ON COLUMNS,

NON EMPTY STRTOSET(@.Query1) * [Dim OverallResult].[Overall Result].[Overall Result] ON ROWS

FROM [OLAP Test Cube]

Report Parameter Name: Query1

Available Non Queried value in Report Parameter is below:

Lable Value

Station [Dim Station].[Station Name].[Station Name]

Free Test [Dim Free Test].[Free Test].[Free Test]

Default Value is below:

Non-Queried value: [Dim Free Test].[Free Test].[Free Test]

I want to Change Column Alias also through Select MDX Query.

let me know if anybody know this?

anyone know about this?|||

This http://www.databasejournal.com/features/mssql/article.php/10894_3504651 article should give you an idea how to use parameters building MDX queries in Reporting Services.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

this is not working for me. any other solution?

in this example they added Dimension member in filter area. I need different dimension in filter area.

Friday, February 17, 2012

create database statement

Where does the SQL Server default the "file name" parameter when you create
a database WITHOUT entering your own parameter for "file name".
You can do a simple "create database somename" and it will create the
database with the defaulted "file name" to be where SQL Server is installed
(location of the mdf and ldf). Does SQL Server take the default location
from the model or master databases or some file group setting?
Thanks in advance
I believe it defaults to the location of model. You can change this in EM
by right-clicking on your server and changing the defaults in the server
properties dialog, or by modifying the registry directly. The defaults are
stored at HKLM\Software\Microsoft\MSSQLServer\MSSQLServer. Two keys:
DefaultData and DefaultLog, which should both be REG_SZ. Note that if you
haven't previously modified this setting in EM, the keys will not yet exist.
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
"Homer" <Homer@.discussions.microsoft.com> wrote in message
news:66B065D1-287D-485E-B3C5-425852D83EFE@.microsoft.com...
> Where does the SQL Server default the "file name" parameter when you
> create
> a database WITHOUT entering your own parameter for "file name".
> You can do a simple "create database somename" and it will create the
> database with the defaulted "file name" to be where SQL Server is
> installed
> (location of the mdf and ldf). Does SQL Server take the default location
> from the model or master databases or some file group setting?
> Thanks in advance
|||The following article should explain the New Database default locations.
Basically though these values are stored in the registry for each SQL server
instance.
http://www.wardyit.com/blog/blog/arc.../11/10/58.aspx
- Peter Ward
WARDY IT Solutions
"Homer" wrote:

> Where does the SQL Server default the "file name" parameter when you create
> a database WITHOUT entering your own parameter for "file name".
> You can do a simple "create database somename" and it will create the
> database with the defaulted "file name" to be where SQL Server is installed
> (location of the mdf and ldf). Does SQL Server take the default location
> from the model or master databases or some file group setting?
> Thanks in advance

create database statement

Where does the SQL Server default the "file name" parameter when you create
a database WITHOUT entering your own parameter for "file name".
You can do a simple "create database somename" and it will create the
database with the defaulted "file name" to be where SQL Server is installed
(location of the mdf and ldf). Does SQL Server take the default location
from the model or master databases or some file group setting?
Thanks in advanceI believe it defaults to the location of model. You can change this in EM
by right-clicking on your server and changing the defaults in the server
properties dialog, or by modifying the registry directly. The defaults are
stored at HKLM\Software\Microsoft\MSSQLServer\MSSQ
LServer. Two keys:
DefaultData and DefaultLog, which should both be REG_SZ. Note that if you
haven't previously modified this setting in EM, the keys will not yet exist.
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--
"Homer" <Homer@.discussions.microsoft.com> wrote in message
news:66B065D1-287D-485E-B3C5-425852D83EFE@.microsoft.com...
> Where does the SQL Server default the "file name" parameter when you
> create
> a database WITHOUT entering your own parameter for "file name".
> You can do a simple "create database somename" and it will create the
> database with the defaulted "file name" to be where SQL Server is
> installed
> (location of the mdf and ldf). Does SQL Server take the default location
> from the model or master databases or some file group setting?
> Thanks in advance|||The following article should explain the New Database default locations.
Basically though these values are stored in the registry for each SQL server
instance.
http://www.wardyit.com/blog/blog/ar...5/11/10/58.aspx
- Peter Ward
WARDY IT Solutions
"Homer" wrote:

> Where does the SQL Server default the "file name" parameter when you cre
ate
> a database WITHOUT entering your own parameter for "file name".
> You can do a simple "create database somename" and it will create the
> database with the defaulted "file name" to be where SQL Server is installe
d
> (location of the mdf and ldf). Does SQL Server take the default location
> from the model or master databases or some file group setting?
> Thanks in advance

create database statement

Where does the SQL Server default the "file name" parameter when you create
a database WITHOUT entering your own parameter for "file name".
You can do a simple "create database somename" and it will create the
database with the defaulted "file name" to be where SQL Server is installed
(location of the mdf and ldf). Does SQL Server take the default location
from the model or master databases or some file group setting?
Thanks in advanceI believe it defaults to the location of model. You can change this in EM
by right-clicking on your server and changing the defaults in the server
properties dialog, or by modifying the registry directly. The defaults are
stored at HKLM\Software\Microsoft\MSSQLServer\MSSQLServer. Two keys:
DefaultData and DefaultLog, which should both be REG_SZ. Note that if you
haven't previously modified this setting in EM, the keys will not yet exist.
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--
"Homer" <Homer@.discussions.microsoft.com> wrote in message
news:66B065D1-287D-485E-B3C5-425852D83EFE@.microsoft.com...
> Where does the SQL Server default the "file name" parameter when you
> create
> a database WITHOUT entering your own parameter for "file name".
> You can do a simple "create database somename" and it will create the
> database with the defaulted "file name" to be where SQL Server is
> installed
> (location of the mdf and ldf). Does SQL Server take the default location
> from the model or master databases or some file group setting?
> Thanks in advance|||The following article should explain the New Database default locations.
Basically though these values are stored in the registry for each SQL server
instance.
http://www.wardyit.com/blog/blog/archive/2005/11/10/58.aspx
- Peter Ward
WARDY IT Solutions
"Homer" wrote:
> Where does the SQL Server default the "file name" parameter when you create
> a database WITHOUT entering your own parameter for "file name".
> You can do a simple "create database somename" and it will create the
> database with the defaulted "file name" to be where SQL Server is installed
> (location of the mdf and ldf). Does SQL Server take the default location
> from the model or master databases or some file group setting?
> Thanks in advance