HOW To Create An SQL User Using Parameters ?

Oct 1, 2007

Hello !

I want to create DB users with an stored procedure, and pass the user name as a parameter.
I wrote this code :

CREATE PROCEDURE [dbo].[spTest]

(


@ComName varchar(20),

)

AS

BEGIN


SET NOCOUNT OFF;

CREATE USER [@ComName] WITHOUT LOGIN WITH DEFAULT_SCHEMA = dbo;

END


If I execute this stored procedure :


DECLARE @return_value int

EXEC @return_value = [dbo].[spTest]

@ComName = N'Test_User',

SELECT 'Return Value' = @return_value

I obtain in my DB an user called "@ComNane" instead of "Test_User" !
Where is my mystake ?

Many thanks for any help.

Luc

View 3 Replies


ADVERTISEMENT

Trying To Create A View With Parameters.

Sep 13, 2007

Trying to create a view with parameters. I want to use view inside the SP. But I'm getting an error. Why?



-- 1st
-- drop table funkete
create table funkete (funketeid int, funketeFname varchar(20))
insert funkete
select 1, 'funkete' union all
select 5, 'amanda' union all
select 6, 'funkete'
go

-- 2nd
-- drop proc a
create proc a (@funketeid int)
as
select @funketeid, funketefname from funkete
go

-- 3rd
exec a @funketeid = 4
go

-- 4th
create view vw_funkete4 as
declare @funketeid int
select @funketeid, funketefname from funkete
go



=============================
http://www.sqlserverstudy.com

View 6 Replies View Related

User.Identity.Name Parameters

Dec 3, 2007

 Hi,I have an on screen control to select data from a table. Here are the parameters for the select:           <asp:Parameter DefaultValue="bezlan" Name="recievername" />
            <asp:Parameter DefaultValue="bezlan" Name="recieversname" />this works perfectly if I sign in as bezlan           <asp:Parameter DefaultValue="User.Identity.Name" Name="recievername" />
            <asp:Parameter DefaultValue="User.Identity.Name" Name="recieversname" /> this doesnt pick up any data at all if I sign in as bezlan.Why is this? Is there a special bit of code I need for parameters?Thanks,Jon 

View 6 Replies View Related

Added Two More User Parameters

Sep 14, 2007



I have a stored procedure that works fine in reporting services. It grabs the total of Yes's and No's by dates . But then i went ahead and added 2 more parameters to the proc, and now the totals are all wrong. I dont understand how that can mess everything up. Here is the previous stored proc, that gives the correct sum.





Code Snippet
ALTER PROCEDURE [dbo].[Testing_Questions_ALL_YESOrNO]
@Question char(80)
AS
BEGIN

SELECT
Qry_Questions.Question
, Qry_Questions.Date
, Qry_Questions.response
, B.Total
FROM Qry_Questions
INNER JOIN Qry_Sales_Group
ON dbo.Qry_Questions.sales_person_code COLLATE SQL_Latin1_General_CP1_CI_AS = dbo.Qry_Sales_Group.SalesPerson_Purchaser_Code
INNER JOIN
( Select COUNT(qq.response)as Total, Question, Date, response
FROM Qry_Questions qq
Where qq.response in ('Yes','No')
GROUP by qq.[Question] , qq.Date,qq.response ) B
ON Qry_Questions.Date = B.Date AND
Qry_Questions.Question =B.Question and
Qry_Questions.response=B.response
WHERE Qry_Questions.[Response Type]='YesNo' and Qry_Questions.Question=@Question
GROUP BY Qry_Questions.question,Qry_Questions.Date,Qry_questions.Response,B.Total
ORDER BY Qry_Questions.Question, Qry_Questions.Date


END
SET NOCOUNT OFF


Here is the edited version which only has two new parameters added to the proc. The edits are highlighted.



Code Snippet
ALTER PROCEDURE [dbo].[Testing_Questions_ALL_YESOrNO_Totals]
(@Region_Key int=null,@QuestionCode char(5),@Question char(80))
AS
BEGIN

SELECT
Qry_Questions.Question
, Qry_Questions.Date
, Qry_Questions.response
, B.Total
FROM Qry_Questions
INNER JOIN Qry_Sales_Group
ON dbo.Qry_Questions.sales_person_code COLLATE SQL_Latin1_General_CP1_CI_AS = dbo.Qry_Sales_Group.SalesPerson_Purchaser_Code
INNER JOIN
( Select COUNT(qq.response)as Total, Question, Date, response
FROM Qry_Questions qq
Where qq.response in ('Yes','No')
GROUP by qq.[Question] , qq.Date,qq.response ) B
ON Qry_Questions.Date = B.Date AND
Qry_Questions.Question =B.Question and
Qry_Questions.response=B.response
WHERE Qry_Questions.[Response Type]='YesNo'
AND REGION_KEY=@Region_Key
AND LEFT(Qry_Questions.[Question Code],2)IN (@QuestionCode)
AND Qry_Questions.Question=@Question
GROUP BY Qry_Questions.question,Qry_Questions.Date,Qry_questions.Response,B.Total
ORDER BY Qry_Questions.Question, Qry_Questions.Date



END
SET NOCOUNT OFF




View 6 Replies View Related

Can I Create Dynamic Report Parameters?

Apr 4, 2007

Hi all,

Is it possible to create a report with dynamic parameters or parameters dependant on other ones? I have the following scenario -



Parameter 1 - 'Select an Application' - List of applications that are available

Parameter 2 - 'Select a module' - This is a list of modules that needs to depend on Parameter 1. As a user selects different applications, the appropriate module list will be loaded.

Is this possible to do in SSRS?



Thanks,

Brian

View 3 Replies View Related

SQL Queries That Have Parameters Passed By User

Jul 23, 2005

I have an sql query that has specific criteria (like state='PA' orstate = 'NJ'...) and would like to be able to have the user specifythe criteria dynamically either through the web or from MSAccess oranother tool.The query also does a GROUP BY the state and other variables that arepart of the criteria.I know how to get MSAccess and asp pages to do the sorting andselecting against an SQL tbl or view, but when access queries the sameinfo as the original sql view, the process takes much longer than whenthe sql view does all of the sorting, selecting and grouping..The table we are currently using is 5 million records and will begrowing to 250 million records shortly, so speed is of the essence.The sql views and MSAccess are both running from the same server sothere is no issue at this point of a network impacting the MSAccessquery.Any suggestions...

View 6 Replies View Related

Visible Parameters That User Cannot Change

Mar 17, 2008

I have a report that I want users to navigate to and I want them to see the parameters of the report, but I don't want them to be able to change them. Is this possible?

View 3 Replies View Related

User-Defined Aggregates With Parameters

Mar 25, 2008

I have to write an aggregate which accumulates values in a relation to a parameter. Therefore I tried to create an aggregate with an additional input parameter.

While creating the aggregate, I get the following error message:
CREATE AGGREGATE failed because type 'MKT' does not conform to UDAGG specification due to method 'Accumulate'.

Does anybody know, how I could solve this?



Public Sub Accumulate(ByVal value As SQLDouble, ByVal param1 as SQLDouble)
Const uGK as double = 0.008

result = result + Math.Exp(-param1/(uGK *value) )
End Sub

View 7 Replies View Related

User Defined Functions && Default Parameters

Jul 23, 2005

Hi,I am trying to call a user defined function(UDF) from a stored proc,using a default parameter in the called UDF (e.g. @bid_price_type int= 0 ). However the calling stored proc complains that the UDF isexpecting a 2nd parameter when I only provide the @test parametervalue. Are default parameter values supported in UDF's?I wld really appreciate anybody's help. Thankyou in advance.UDF code:CREATE FUNCTION get_bid_price (@test int, @bid_price_type int = 0)RETURNS decimal(18, 4) ASBEGINdeclare @x decimal(18, 4)if (@bid_price_type = 0)beginselect @x = fieldNamefromtableNameendelsebeginselect @x = fieldName2fromtableName2endreturn @xEND' Calling Stored Proc codeCREATE PROCEDURE testASdeclare @x decimal(18, 4)set @x = dbo.get_bid_price(1)select @xGOthanks,Vic Y

View 2 Replies View Related

Storing Default Parameters As User Preference

Nov 29, 2007



Need some guidelines:

I wanted to create a report with parameters. The users will access the reports via
http://localhost/Reportserver/myReportName

Now, each user will have their own default parameters and would like to be stored(somewhere!!!) as "user preference", so nexttime when they access this report it should display data with the "user preference" parameters.

Can someone give me some advise to implement this.

Many thanks.

View 5 Replies View Related

Parameters - User Running Ther Report

Apr 25, 2008

Hello,
Does anyone know how to pass the userid (domainaccount) of the person runnig the report to the proc underneath. With asp.net calling Crystal Reports, this was simple.

Jeremy

View 7 Replies View Related

What's The Best Way To Create A Stored Procedure That Queries With Multiple Parameters?

Nov 21, 2007

 
If I were to create a stored procedure that searches a table using (optional) multiple parameters, what would be the best way to do the search.  I want to try and avoid using several "IF" statements (like IF @FirstName IS NOT NULL, etc).  How would I do it, or would I just be better off using several "IF" statements?  Thanks...
 CREATE PROCEDURE intranet_search_GetEmployeesBySearch
(
@FirstName NVarChar(100),
@LastName NVarChar(100),
@Phone NVarChar(50),
@Cell NVarChar(100),
@Pager NVarChar(100),
@Ext NVarChar(50),
@Email NVarChar(100),
@Department NVarChar(200),
@Position NVarChar(100),
@IsManager Bit
)
AS
BEGIN

SET NOCOUNT ON;




END
GO 

View 8 Replies View Related

How To Create Cascading Parameters In A Report With Cube As Datasource

Mar 11, 2008



I'm trying to create report with datasource as a cube. I'm able to connect to datasource to pull data with a single parameter. But, I'm unable to succeed in creating a cascading parameter.
The following scenario:
I have a dimension "Period" as Paremeter.
The Period dimension is cascaded to year- quarter- month.
So, I would like to create a cascading parameter for period as year - quarter - month.

Please let me know, how to acheive this.

thanks,
Naveen.

View 5 Replies View Related

Schedule A Report To Run At A Particular Time With User Filled Parameters

Mar 23, 2007

I have a report that I would like to run in the evening due to high database usage that required a user to fill in selected parameters. Is there anyway to allow a user to fill in the report parameters and have it scheduled to run at 3:00 AM.

Thanks,

Chris

View 6 Replies View Related

How To Create Radio Buttons For Parameters In Reporting Services 2005

Nov 15, 2007



Hello,

I am creating a report that the user will pick a value from about 6 items. The project manager would like these values to be represented as radio buttons on the ReportViewer control. I am unable to determine how do create these 6 radio buttons.

Here is a simple example to demonstrate what I need. Lets say the report returns the total number of fruit in a stores inventory. The choices are: Apple, Banannas, Oranges, Grapes, Cherries, Water Mellon.

I have a variable @Fruit that I would like populated by the user and I want them to select which piece of fruit they want to see by selecting a radio button. Is there a way to do this using Reporting Services 2005 Report Designer?

Thanks,
Flea#

View 5 Replies View Related

User Defined Data Type Used In Stored Procedure Parameters

Jul 23, 2005

I have several stored procedures with parameters that are defined withuser defined data types. The time it takes to run the procedures cantake 10 - 50 seconds depending on the procedure.If I change the parameter data types to the actual data type such asvarchar(10), etc., the stored procedure takes less that a second toreturn records. The user defined types are mostly varchar, but someothers such as int. They are all input type parameters.Any ideas on why the stored procedure would run much faster if notusing user defined types?Using SQL Server 2000.Thanks,DW

View 13 Replies View Related

User Defined Functions, Passing Parameters From Another Udf's Results (end Result=Crosstab)

Oct 25, 2005

Hi All:I've read a whole slew of posts about creating temp tables using storedproceedures to get the crosstab ability, but I'm wondering if, for thisspecific case, there might be a more efficient way.What makes this question different from the others that I've read isthat I'm using user defined functions, not tables. I actually thinkthat I've got the crosstab thing down, it's just passing the parameterto the 2nd udf that's messing me up.I've got a people table and an address table. Each person can havemultiple addresses. I need to create a dataset that has in each rowthe name of the person, the first address, any second address, and anythird address. I only need to show the first 3, so if there's 100, Ican just ignore the rest.I created a user defined function to return the 1st, 2nd, or 3rdaddress for a given person.udf_ReturnAddress(PersonID,MatchNumber)Another user defined function returns the people that I'm looking for(potential duplicates for a person in this case).udf_ReturnPossibleDupsForAPerson(PersonID)SELECTMain.FoundPersonID, Main.LastName, A1.Street, A2.Street,A3.StreetFROMudf(ReturnPossibleDupsForAPerson(@PersonID) MainTableCROSS JOIN(SELECT Street1 FROMudf_ReturnAddress(Main.FoundPersonID,1) Adr1) A1CROSS JOIN(SELECT Street1 FROMudf_ReturnAddress(Main.FoundPersonID,2) Adr2) A2CROSS JOIN(SELECT Street1 FROMudf_ReturnAddress(Main.FoundPersonID,3) Add3) A3If, for the first parameter for the return address function, I replaceMain.FoundPersonID with the ID of a person, it works just fine. Iobviously don't want a static id as a parameter - I want to use the IDof the person that the first udf found. Leaving the variableMainTable.PersonID there causes an error in the query designer though.I get "Error in list of function arguments: '.' not recognized.So maybe my problem is that I just don't know how to pass the id of theperson that's found by the first UDF as the parameter of the functionto find the found person's 3 addresses.Any guidance would be greatly appreciated!ThanksKen

View 6 Replies View Related

How To Use A Stored Procedure With Parameters To Create The Datasource View For Report Model Builder

Mar 12, 2007

I have a stored procedure that takes a date range and returns all the sales in that date range. I'm trying to create the report model for ad-hoc reporting. When I go to create the dataset view, it only lets me select tables or views.... how do I get around this?

View 2 Replies View Related

How To Show The User Selected Values In Page Header By Using Parameters Which I Have Already Created In The Report

Dec 10, 2007

Hi ,

I am working on Sql server Reporting Services(Sql Server 2005),

i have designed a Report and deployed that report on Report Server, on this report i need to show the user selected values
in page header by using Parameters which i have already created in the Report.

There are 35 to 40 fields in the Front End(Asp.net2.0)

on passing all these values from front end Report is prompting for parameters which is not desired for my case even though i have made ShowParameterPrompts to false.



Thanks in advance

Srinivas Govada

View 1 Replies View Related

Vb.net Create User

Dec 18, 2007

I am trying to create a program that user inputs the sa password and it creates a user in SQL Express 2005 installation.  Is this possible?  If so can someone point me in the right direction?

View 5 Replies View Related

Create User

Apr 28, 2000

Hello,

I would like to create a new database user using T-Sql command. Somebody Knows?

Thanks,
Hugo Venturini

View 2 Replies View Related

Create User Help

Jan 25, 2007

hi,

i am new to mssqlserver 2005, i installed it successfully in my localhost, problem is i cant create user it gives me:

'my_aro' is not a valid login or you do not have permission

how can i create a user?

View 2 Replies View Related

Create A RO User For All DBs

Feb 2, 2007

In SQL 2005, I want to create a RO_user with read only access rights to some of my databases. I wrote the folloiwng code but get an error in USE @db_name.

Is there an easier way to create the user id and grant the RO access right to it? I have about 500 databases.


USE [Master]
GO

DECLARE @db_name nvarchar(50)

DECLARE db_cursor CURSOR FOR
SELECT master.dbo.[name]
FROM sysdatabases
WHERE Substring(name,1,4) in ('DB06', 'AC06', 'RE07')

OPEN db_cursor

FETCH NEXT FROM db_cursor INTO @db_name

WHILE @@FETCH_STATUS = 0
BEGIN

USE @db_name
CREATE USER [RO_user] FOR LOGIN [RO_user]
EXEC sp_addrolemember N'db_datareader', N'RO_user'

FETCH NEXT FROM db_cursor INTO @db_name
END
CLOSE db_cursor
DEALLOCATE db_cursor


Canada DBA

View 3 Replies View Related

Create A New User

Jul 20, 2005

Hello,How can I create a new user with password for the MS SQL - Server 2000(and the MSDE) with a SQL - Statement? I use Borland Delphi 5 with theADO - Components!Thanks.best regards.Stephan Jahrling

View 1 Replies View Related

Create A New User

Mar 15, 2007

hi

im unable to create a new sql server authentication login

It is appreciated if anyone helps me

thanks in advance

View 4 Replies View Related

How To Create New User?

Jan 7, 2007

Hi,

i'm using SQL server 2005 and I need to create new login/user. Previously I used MySQL where user management is much simplier, so I need a help with SQL server. I run following script:

EXEC sp_addlogin 'uzivatele', @passwd = 'xyz', @defdb = 'master', @deflanguage = 'Czech'
GO

EXEC sp_addsrvrolemember 'uzivatele', 'sysadmin'
GO


GRANT CONNECT SQL TO [uzivatele]
GO

CREATE USER [jirka]
FOR LOGIN [uzivatele]
GO



But when I try to connect o database "master" as user "jirka" with password "xyz", it fails with message "Login failed for user 'jirka'". What do I wrong?

thanks

Jiri Matejka




View 1 Replies View Related

Create User

Jun 10, 2007

Hi,

how can i create a user in a stored procedure. the user has to be able to connect to my database

thanks.

View 3 Replies View Related

How To Create A User With Sa Privilege

Feb 16, 1999

Using SQL 6.5 SP4.
TIA.
Zak

View 2 Replies View Related

Create User Scripts

Aug 21, 2007

i need a scripts which should create a user with dbo privileges on the particular database please help

View 2 Replies View Related

Create User Form

Oct 7, 2007

hello there,

Can i create user forms for user to select options and then present them with data based on their selection.i want to be able to use check boxs and combo box.thanks in advance

cheers
zolf

View 1 Replies View Related

Create User Error!

Jan 30, 2006

I have just managed to have JDBC working, but I am getting an error that the user does not exist. I have read in the MSDN help that I need to set the sqlExpress to accept SQL server authentication and not windows authentication. So when I am trying to create a new User using Microsoft SQL server management studio express I get the following error.



TITLE: Microsoft SQL Server Management Studio Express
------------------------------

Create failed for Login 'adam'. (Microsoft.SqlServer.Express.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+Login&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)

------------------------------

The MUST_CHANGE option is not supported by this version of Microsoft Windows. (Microsoft SQL Server, Error: 15195)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.1399&EvtSrc=MSSQLServer&EvtID=15195&LinkId=20476


View 5 Replies View Related

Create User Form

Oct 7, 2007

hello there,

Can i create user forms for user to select options and then present them with data based on their selection.i want to be able to use check boxs and combo box.thanks in advance

cheers
zolf

View 5 Replies View Related

Create A List If User

Jun 1, 2007

Hi there,



Can someone please help me how to generate the list of all "user" in a database and it's access role? really need it . .



Thanks

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved