Showing posts with label procedure. Show all posts
Showing posts with label procedure. Show all posts

Friday, March 30, 2012

Scripting automation....

Is there any stored procedure for scripting the database?
SQL 2K.
Thanks,
Johnhttp://www.karaszi.com/SQLServer/in...rate_script.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Smith John" <Smith_Jr@.hotmail.com> wrote in message news:OZXYRiK3FHA.548@.TK2MSFTNGP10.phx.g
bl...
> Is there any stored procedure for scripting the database?
> SQL 2K.
> Thanks,
> John
>
>
>|||There is no sp; you can use DMO (Distributed Management Objects) in some
scripting language. You can execite ActiveX script task in a scheduled job.
Here is an example of using DMO in vbscript :
Dim oSS As SQLDMO.SQLServer
Dim oDb As SQLDMO.Database
Dim oT As SQLDMO.Transfer
Dim sS As String
Sub Script()
Set oSS = New SQLDMO.SQLServer
Set oT = New SQLDMO.Transfer
oSS.LoginSecure = True
oSS.Connect
Set oDb = oSS.Databases("pubs")
oT.CopyAllTables = True
oDb.ScriptTransfer oT, SQLDMOXfrFile_SingleFile, "C:\pubs.sql"
End Sub
Dejan Sarka, SQL Server MVP
Mentor
www.SolidQualityLearning.com
"Smith John" <Smith_Jr@.hotmail.com> wrote in message
news:OZXYRiK3FHA.548@.TK2MSFTNGP10.phx.gbl...
> Is there any stored procedure for scripting the database?
> SQL 2K.
> Thanks,
> John
>
>
>|||I was searching for this article of yours a minute ago, but somehow I
couldn't find it...
Dejan Sarka
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uhNyQuK3FHA.472@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> http://www.karaszi.com/SQLServer/in...rate_script.asp
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Smith John" <Smith_Jr@.hotmail.com> wrote in message
> news:OZXYRiK3FHA.548@.TK2MSFTNGP10.phx.gbl...

Scripting automation....

Is there any stored procedure for scripting the database?
SQL 2K.
Thanks,
John
http://www.karaszi.com/SQLServer/inf...ate_script.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Smith John" <Smith_Jr@.hotmail.com> wrote in message news:OZXYRiK3FHA.548@.TK2MSFTNGP10.phx.gbl...
> Is there any stored procedure for scripting the database?
> SQL 2K.
> Thanks,
> John
>
>
>
|||There is no sp; you can use DMO (Distributed Management Objects) in some
scripting language. You can execite ActiveX script task in a scheduled job.
Here is an example of using DMO in vbscript:
Dim oSS As SQLDMO.SQLServer
Dim oDb As SQLDMO.Database
Dim oT As SQLDMO.Transfer
Dim sS As String
Sub Script()
Set oSS = New SQLDMO.SQLServer
Set oT = New SQLDMO.Transfer
oSS.LoginSecure = True
oSS.Connect
Set oDb = oSS.Databases("pubs")
oT.CopyAllTables = True
oDb.ScriptTransfer oT, SQLDMOXfrFile_SingleFile, "C:\pubs.sql"
End Sub
Dejan Sarka, SQL Server MVP
Mentor
www.SolidQualityLearning.com
"Smith John" <Smith_Jr@.hotmail.com> wrote in message
news:OZXYRiK3FHA.548@.TK2MSFTNGP10.phx.gbl...
> Is there any stored procedure for scripting the database?
> SQL 2K.
> Thanks,
> John
>
>
>
|||I was searching for this article of yours a minute ago, but somehow I
couldn't find it...
Dejan Sarka
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uhNyQuK3FHA.472@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> http://www.karaszi.com/SQLServer/inf...ate_script.asp
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Smith John" <Smith_Jr@.hotmail.com> wrote in message
> news:OZXYRiK3FHA.548@.TK2MSFTNGP10.phx.gbl...

Scripting automation....

Is there any stored procedure for scripting the database?
SQL 2K.
Thanks,
Johnhttp://www.karaszi.com/SQLServer/info_generate_script.asp
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Smith John" <Smith_Jr@.hotmail.com> wrote in message news:OZXYRiK3FHA.548@.TK2MSFTNGP10.phx.gbl...
> Is there any stored procedure for scripting the database?
> SQL 2K.
> Thanks,
> John
>
>
>|||There is no sp; you can use DMO (Distributed Management Objects) in some
scripting language. You can execite ActiveX script task in a scheduled job.
Here is an example of using DMO in VBScript:
Dim oSS As SQLDMO.SQLServer
Dim oDb As SQLDMO.Database
Dim oT As SQLDMO.Transfer
Dim sS As String
Sub Script()
Set oSS = New SQLDMO.SQLServer
Set oT = New SQLDMO.Transfer
oSS.LoginSecure = True
oSS.Connect
Set oDb = oSS.Databases("pubs")
oT.CopyAllTables = True
oDb.ScriptTransfer oT, SQLDMOXfrFile_SingleFile, "C:\pubs.sql"
End Sub
--
Dejan Sarka, SQL Server MVP
Mentor
www.SolidQualityLearning.com
"Smith John" <Smith_Jr@.hotmail.com> wrote in message
news:OZXYRiK3FHA.548@.TK2MSFTNGP10.phx.gbl...
> Is there any stored procedure for scripting the database?
> SQL 2K.
> Thanks,
> John
>
>
>|||I was searching for this article of yours a minute ago, but somehow I
couldn't find it...
--
Dejan Sarka
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uhNyQuK3FHA.472@.TK2MSFTNGP15.phx.gbl...
> http://www.karaszi.com/SQLServer/info_generate_script.asp
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Smith John" <Smith_Jr@.hotmail.com> wrote in message
> news:OZXYRiK3FHA.548@.TK2MSFTNGP10.phx.gbl...
>> Is there any stored procedure for scripting the database?
>> SQL 2K.
>> Thanks,
>> John
>>
>>

Wednesday, March 28, 2012

Script works in DTS, but has problems as a Stored Procedure

I have a script that builds multiple tables and then builds tables from those tables, etc..

Usually, I run the script as a DTS package, and it doesn't have any problems. However, when I save the script as a stored procedure, I think it is compiling the table builds into a different sequence.

As a result, some of the tables are blank when this script is run as a stored procedure.

Do I need to use transactions to prevent this compilation problem, or is there an easier setting that I can use to keep everything in the original sequence?

Thanks in advance.Anyone have any ideas on this? I can't use "GO", but I am still still having this compilation issue.sql

Monday, March 26, 2012

Script to identify line count in an procedure

Hi Guys,
Do any one of you have any scripts which return the procedure name and
number of lines for all procedures in a database.
Say I have a server with 1000 stored procedure,I need a script which return:
Procedure name Number of lines
-- --
Thanks in advance
HariI think this should do it:
SELECT O.name, SUM(LEN(text)-LEN(REPLACE(text,CHAR(13),'')))
FROM syscomments AS C
JOIN sysobjects AS O
ON C.id = O.id
WHERE O.xtype='P'
GROUP BY O.id, O.name
--
David Portas
--
Please reply only to the newsgroup
--|||Thanks a lot.
Regards
Hari
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:iMidnTtJieiJzlqiRVn-gQ@.giganews.com...
> I think this should do it:
> SELECT O.name, SUM(LEN(text)-LEN(REPLACE(text,CHAR(13),'')))
> FROM syscomments AS C
> JOIN sysobjects AS O
> ON C.id = O.id
> WHERE O.xtype='P'
> GROUP BY O.id, O.name
> --
> David Portas
> --
> Please reply only to the newsgroup
> --
>

Tuesday, March 20, 2012

Script SP with permission automatically

Hi,

In enterprise manager, there is a option to automatically script any trigger, permission on a table or store procedure. It seems that this feature is gone from new the SQL management studio. Is there a way to easy script this easily just like before?

thanks,

Bernie

Hi there,

Well, you can script triggers by going to the specific table in the Object Explorer and expanding the node for that table....There should be a sub-node for triggers which you can expand to see the triggers defined on the table. Right click on the desired trigger and select "Script Trigger As" from the context menu that appears.

Note that you can take the same action for most of the other sub-nodes you see under the table such as Constraints, Indexes and Keys.

As for scripting objects with permissions, I believe that you will need to use the Script Wizard to do this. To access the wizard you right click on a database and from the context menu that appears you select: Tasks > Generate Scripts

The Script Wizard will now appear. You can run through it as follows:

1) Click the "Next>" button on the initial screen

2) Select the database you want to script and then click the "Next>" button. You can also tick the "Script All Objects In The Selected Database" option if you want to script absolutely everything

3) You will be prompted to select scripting options such as scripting object permissions, table triggers and constraints etc. Review the options and select the ones that are right for you

4) If you did not select the "Script All Objects In The Selected Database" option, you will now get to choose which database objects (e.g. stored procedures) to script and will run through a series of screens in order to make your selection

It's pretty much smooth sailing after that.

Hope that helps a bit, but sorry if it doesn't

|||

sql server management studio 2005 has a better scripting support than sql server enterprise manager 2000.

you can right click the object and the choose "script object to ; alter ; create ; delete;"

yet another way to do it is to right click the object and then choose properties

on the top portion of the properties tab there's a clcikable script dropdown which allows you to script to clipboard, file, jobs or to new query window. on the left hand side of the properties window there's a listbox with the following item geneneral,permission, extended properties. to script permission, choose permission from the list and then click the script dropdown

here's another

You can also right click the database then task then choose then choose generate scripts. this will lunch the scripts wizard which is somewaht similar to those of the EM

Script or Stored Procedure that Collects Information from a Database

Information such as:
1. Database Name
2. Users
3. Database Properties (e.g., size, number of tables, etc.)
4. Other information of interest to a DBA (e.g., Maintenance Plan and
if the last job ran successfully)
I know there are umteen utilities out there that can derive this
information. I would like the product to derive its own information
using scripts or stored procs.
Thanks for any suggestions!
RBollinger
If you run profiler while you look through the GUI's for this info, you can
see the tsql they are generating. This can help you build your own tools.
Jason Massie
www: http://statisticsio.com
rss: http://feeds.feedburner.com/statisticsio
"robboll" <robboll@.hotmail.com> wrote in message
news:3ffe6464-ae36-47f9-94c4-14fb02266d23@.60g2000hsy.googlegroups.com...
> Information such as:
> 1. Database Name
> 2. Users
> 3. Database Properties (e.g., size, number of tables, etc.)
> 4. Other information of interest to a DBA (e.g., Maintenance Plan and
> if the last job ran successfully)
> I know there are umteen utilities out there that can derive this
> information. I would like the product to derive its own information
> using scripts or stored procs.
>
> Thanks for any suggestions!
> RBollinger

Script or Stored Procedure that Collects Information from a Database

Information such as:
1. Database Name
2. Users
3. Database Properties (e.g., size, number of tables, etc.)
4. Other information of interest to a DBA (e.g., Maintenance Plan and
if the last job ran successfully)
I know there are umteen utilities out there that can derive this
information. I would like the product to derive its own information
using scripts or stored procs.
Thanks for any suggestions!
RBollingerIf you run profiler while you look through the GUI's for this info, you can
see the tsql they are generating. This can help you build your own tools.
--
Jason Massie
www: http://statisticsio.com
rss: http://feeds.feedburner.com/statisticsio
"robboll" <robboll@.hotmail.com> wrote in message
news:3ffe6464-ae36-47f9-94c4-14fb02266d23@.60g2000hsy.googlegroups.com...
> Information such as:
> 1. Database Name
> 2. Users
> 3. Database Properties (e.g., size, number of tables, etc.)
> 4. Other information of interest to a DBA (e.g., Maintenance Plan and
> if the last job ran successfully)
> I know there are umteen utilities out there that can derive this
> information. I would like the product to derive its own information
> using scripts or stored procs.
>
> Thanks for any suggestions!
> RBollinger

Monday, March 12, 2012

script for login transfer from one phy server to another

Hi,

Do you have any idea about the procedure for transferring the logins and password from source server to the destination server.

scenario is as follows

serv - A wanto transfer to ms sql 2000 server - B
running on 6.5 ------------> will be sql2k
(Old server) (new server)

will appriciate if any weblink containg the check list.

with best regards

ranjanI have a script that generates SQL for recreating logins, user, roles, and permissions on SQL 2000 databases. It may run on your 6.5 database.
It will not, however, restore passwords, and I'm not sure you can do this.

Have you thought about running the upgrade on your 6.5 databases (or a copy of them)? It's been a while, but I think this retains the old passwords.

blindman|||Thanx for reply,

Detail of my upgradation plan -

- I am planning to upgrade my db server (mssql-6.5) to server
(mssql2k) on the same machine.

- I have prepared the checklist for that , Only thing I want is a script
which will take care of transferring my ( login name & passoword)
from 6.5 server to 2000 server.

- will appriciate if you can help me in writting the script or foreward a
readymade script.

thanx regards

Ranjan|||Sorry, but I don't have a script for that. Are you sure that the upgrade process won't do this?
As a matter of fact, I think Microsoft changed its encryption algorythm between versions 6.5 and 2000, so even if you copied the encrypted value to the new server it might not recognize your password. If you are looking for a method of decrypting the password, I don't have one but I know it has been cracked (the algorythm was not very strong). You can probably find code for decrypting it on the web.

blindman|||Refer to this KBA (http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q246/1/33.ASP&NoWebContent=1) to accomplish the task.

Friday, March 9, 2012

Script for Creating a Stored Procedure??

Hello,
I'm trying to create a store procedure from an interface which is similiar to Query Analyzer, but I can't get it to work and I don't get an error message...so I'm not sure what error I am receiving. Please see the below sp_get_topics (#1) which is not saving and sp_get_topics (#2 works). Thanks in advance...

--#1--
CREATE PROCEDURE [sp_get_topics] AS
SELECT t_1.Topic, t_1.Message, t_1.Create_Date, t_2.Username
FROM t_1 WITH (READUNCOMMITTED) LEFT OUTER JOIN
t_2 WITH (READUNCOMMITTED) ON t_1.User_ID = t_2.ID
GO

--#2--
CREATE PROCEDURE [sp_get_topics]
AS
SELECT Topic, Message, Create_Date
FROM t_1
GOWhen you're saying that it "is not saving" you mean you can't compile it?|||I hope this is intentional to demonstrate your dilemna but both procs have the same name.|||Which version of sql server are you using ?|||Originally posted by rnealejr
Which version of sql server are you using ?

1) I hope this is intentional to demonstrate your dilemna but both procs have the same name. -- right...I'm trying to compile it with different names, so there's no conflict.

2) Which version of sql server are you using ? -- 2000|||Originally posted by rdjabarov
When you're saying that it "is not saving" you mean you can't compile it?

Yes, I meant "compile it".|||Replace READUNCOMMITTED with NOLOCK|||uuummmmmmmmmmmmmmmmmmmmmmmmmm

Why aren't you using QA?|||Originally posted by rdjabarov
Replace READUNCOMMITTED with NOLOCK

Yeah...I've tried with & without WITH (READUNCOMMITTED) and WITH (NOLOCK), still doesn't work. I'm working with a crappy Entreprise Manager which is web based interface, so that's probably the problem.

Any ideas? Thanks again...|||Originally posted by Brett Kaiser
uuummmmmmmmmmmmmmmmmmmmmmmmmm

Why aren't you using QA?

please read below...thanks.|||Why do you want uncommitted data?

Don't you think that would be dangerous and be a problem with data integrity?

And why can't you install the client tools locally?|||Originally posted by Brett Kaiser
Why do you want uncommitted data?

Don't you think that would be dangerous and be a problem with data integrity?

And why can't you install the client tools locally?

I'm not planning on sticking with the "WITH (readuncommitted)"...I'm just trying every possible way to get this annoying interface to work.

You're right if I was worried about data integrity I wouldn't want to go this route...but it's just a personal site of mine. And still I don't want to use it.

Install the client tools locally? -- I'm using a my web hosts crappy ASP.Net Enterprise Manager (www.aspenterprisemanager.com) version to manipulate my sql tables (which is I guess an old version), so I have to use scripts to create all tables & stored procedures within their version of Query Analyzer. I guess there is a better version out there somewhere, but I haven't been able to get the feedback to know how to setup it up. I would love to use my SQL Server Enterprise Manager locally, but don't know how. If you have any ideas...please let me know.

script file from stored procedure

Hi
Can anybody tell me how I call a sql script file(or any file for that
matter) from within a stored procedure? e.g. file on c:\filename.sql
I want the procedure to retrieve the file and also to run it.
Thanks in advance
The simplest way to do this is using xp_cmdshell to call ISQL or OSQL.
There is no direct TSQL command that allows you to run a script stored in a
file.

Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"jonjo" <jonjo@.discussions.microsoft.com> wrote in message
news:21A98D8B-C58A-46E3-B8A4-D6D115AE9744@.microsoft.com...
> Hi
> Can anybody tell me how I call a sql script file(or any file for that
> matter) from within a stored procedure? e.g. file on c:\filename.sql
> I want the procedure to retrieve the file and also to run it.
> Thanks in advance
|||You can use xp_cmdshell and oSql to do this.
Andrew J. Kelly SQL MVP
"jonjo" <jonjo@.discussions.microsoft.com> wrote in message
news:21A98D8B-C58A-46E3-B8A4-D6D115AE9744@.microsoft.com...
> Hi
> Can anybody tell me how I call a sql script file(or any file for that
> matter) from within a stored procedure? e.g. file on c:\filename.sql
> I want the procedure to retrieve the file and also to run it.
> Thanks in advance

script file from stored procedure

Hi
Can anybody tell me how I call a sql script file(or any file for that
matter) from within a stored procedure? e.g. file on c:\filename.sql
I want the procedure to retrieve the file and also to run it.
Thanks in advanceThe simplest way to do this is using xp_cmdshell to call ISQL or OSQL.
There is no direct TSQL command that allows you to run a script stored in a
file.
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"jonjo" <jonjo@.discussions.microsoft.com> wrote in message
news:21A98D8B-C58A-46E3-B8A4-D6D115AE9744@.microsoft.com...
> Hi
> Can anybody tell me how I call a sql script file(or any file for that
> matter) from within a stored procedure? e.g. file on c:\filename.sql
> I want the procedure to retrieve the file and also to run it.
> Thanks in advance|||You can use xp_cmdshell and oSql to do this.
Andrew J. Kelly SQL MVP
"jonjo" <jonjo@.discussions.microsoft.com> wrote in message
news:21A98D8B-C58A-46E3-B8A4-D6D115AE9744@.microsoft.com...
> Hi
> Can anybody tell me how I call a sql script file(or any file for that
> matter) from within a stored procedure? e.g. file on c:\filename.sql
> I want the procedure to retrieve the file and also to run it.
> Thanks in advance

script file from stored procedure

Hi
Can anybody tell me how I call a sql script file(or any file for that
matter) from within a stored procedure? e.g. file on c:\filename.sql
I want the procedure to retrieve the file and also to run it.
Thanks in advanceThe simplest way to do this is using xp_cmdshell to call ISQL or OSQL.
There is no direct TSQL command that allows you to run a script stored in a
file.
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"jonjo" <jonjo@.discussions.microsoft.com> wrote in message
news:21A98D8B-C58A-46E3-B8A4-D6D115AE9744@.microsoft.com...
> Hi
> Can anybody tell me how I call a sql script file(or any file for that
> matter) from within a stored procedure? e.g. file on c:\filename.sql
> I want the procedure to retrieve the file and also to run it.
> Thanks in advance|||You can use xp_cmdshell and oSql to do this.
--
Andrew J. Kelly SQL MVP
"jonjo" <jonjo@.discussions.microsoft.com> wrote in message
news:21A98D8B-C58A-46E3-B8A4-D6D115AE9744@.microsoft.com...
> Hi
> Can anybody tell me how I call a sql script file(or any file for that
> matter) from within a stored procedure? e.g. file on c:\filename.sql
> I want the procedure to retrieve the file and also to run it.
> Thanks in advance

Script database using stored procedure

Is it possible to use a stored procedure to script an entire database in MS SQL 2000?You can use the CREATE DATABASE statement in a stored proc.

What you can't do is run the following:

CREATE VIEW , CREATE PROC, CREATE RULE, CREATE DEFAULT , CREATE RULE

You can script the entire database from enterprise manager which would be sufficient for the any purpose i can think of.

Stored Procs should be used for heavily repeated processes not one off's.

Hope this helps ...|||Yes it is possible, but is bad idea... maybe better SQLDMO?

sp_helptext
Prints the text of a rule, a default, or an unencrypted stored procedure, user-defined function, trigger, or view.
Syntax
sp_helptext [ @.objname = ] 'name'

sp_help
Reports information about a database object (any object listed in the sysobjects table), a user-defined data type, or a data type supplied by Microsoft SQL Server.

Syntax
sp_help [ [ @.objname = ] name ]

http://www.apexsql.com/|||well not exactly, let me explain.

What I want to do is call a procedure that exports the entire database design (tables views etc) to a sql-script file.

Pretty much the same as the server is able to do in the enterprise manager. The only difference is, that I want to be able to call the procedure from an application.

Clearer?

Rolf|||Hi Rolf,

What you might want to do is use DTS to copy the objects across to whatever server you wish

have a look at DTS - Copy SQL Server Objects

You can set this to copy the objects but not the data

If you need to call this from an application then you can use the cmd line DTSRun utility which will allow you to run it from a cmd prompt.

Hope this helps .....|||OK thanks,

I know of this possibility but I'd prefer to avoid it.

thanks anyway.

R.|||I swear that at one time I found a command-line utility that I could call from xp_cmdshell to output a database script identical to Enterprise Manager's scripting results. But now I can't find it. :(

I'll keep looking, but in the meantime check out the SQL-DMO SCRIPT method in Books Online.|||Now we're getting somewhere. I'll try this first and will return if it doesn't work.

Thanks.

R.|||There is sample VB app from Micosoft on how to use the SQL-DMO Script methods referenced in SQL Server Books Online. If interested, look in the Books Online index for "SQL-DMO", then "samples", then "SQLScripts".

I found the source on my machine in a file named GenSQLScriptsDemo.zip.

Saturday, February 25, 2012

SCPTXFR.EXE-- Problem with Drop procedure

hi there
I am using SCPTXFR.EXE to generate script of the database(for backup),using following command.

SCPTXFR.EXE /s abc /d aaa /P abc12345 /f D:\HSE0607\SCHEMA.sql /q/r/T

Now the script is generating fine, but what i find that there is no statment like
"if not exists(...) "
for the Stored Procedure( i had applied the /r parameter), for the Create Tables it is there.

Why there is no statment IF NOT EXISTS(...) for Stored Procedure?
I need this Line, how can i do this?
Regards,
Thanks.
Gurpreet S. Gill

hey nobody help me here, but i find the solution at

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=73290

Tuesday, February 21, 2012

SCOPE_INDENTITY() Not Returning

Dear All,

My newly insert GUID is not return from a store procedure. I turned this
around and around and can't understand why. The records are inserted but no
GUID is returned.

I use (newid()) in the table to generate a GUID

**************Store Procedure ***********************
CREATE PROCEDURE heasvase.[usp_insert_address]

@.ADDR_NAME_2 [char](70) = NULL,
@.ADDR_NO_3 [char](10) = NULL,
@.ADDR_ROAD_4 [char](50) = NULL,
@.ADDR_DISTRICT_5 [char](50) = NULL,
@.ADDR_TOWN_6 [char](50) = NULL,
@.ADDR_BOROUGH_7 [char](50) = NULL,
@.ADDR_PCODE_8 [char](12) = NULL,
@.addr_id [int] OUTPUT
AS

INSERT INTO [HEAPADLive].[dbo].[TBL_ADDR]
(
[ADDR_NAME],
[ADDR_NO],
[ADDR_ROAD],
[ADDR_DISTRICT],
[ADDR_TOWN],
[ADDR_BOROUGH],
[ADDR_PCODE])

VALUES
(
@.ADDR_NAME_2,
@.ADDR_NO_3,
@.ADDR_ROAD_4,
@.ADDR_DISTRICT_5,
@.ADDR_TOWN_6,
@.ADDR_BOROUGH_7,
@.ADDR_PCODE_8)

SELECT @.addr_id = scope_identity()
GO

***************** ASP ***********************
'Set connection and command properties
set objConn = Server.CreateObject("ADODB.Connection")
set objComm = Server.CreateObject("ADODB.Command")

objConn.Open "Provider=SQLOLEDB.1; Integrated Security=SSPI; Persist
Security Info=False;User ID=iusr_abc; Initial Catalog=Cat_name; Data
Source=SQLSER7"
objComm.ActiveConnection = objConn
objComm.CommandType = adCmdStoredProc
objComm.CommandText = "heasvase.usp_insert_address"

'Set parameters
set value1 = objComm.CreateParameter("@.val1", adChar, adParamInput, 20 ,
val1)
set value2 = objComm.CreateParameter("@.val2", adChar, adParamInput, 20 ,
val2)
set value3 = objComm.CreateParameter("@.val3", adChar, adParamInput, 20 ,
val3)
set value4 = objComm.CreateParameter("@.val4", adChar, adParamInput, 20 ,
val4)
set value5 = objComm.CreateParameter("@.val5", adChar, adParamInput, 20 ,
val5)
set value6 = objComm.CreateParameter("@.val6", adChar, adParamInput, 20 ,
val6)
set value7 = objComm.CreateParameter("@.val7", adChar, adParamInput, 20 ,
val7)
set value8 = objComm.CreateParameter("@.addr_id", adInteger, adParamOutput )

objComm.Parameters.Append(value1)
objComm.Parameters.Append(value2)
objComm.Parameters.Append(value3)
objComm.Parameters.Append(value4)
objComm.Parameters.Append(value5)
objComm.Parameters.Append(value6)
objComm.Parameters.Append(value7)
objComm.Parameters.Append(value8)

'Run Command and tell ADO no records only potput params 'adExecuteNoRecords'
objComm.Execute , , adExecuteNoRecords

newId = objComm.Parameters.Item("@.addr_id")

response.write("Here ->" & newId)

'Cleanup resources
Set objComm = Nothing

Any help would be greatly appreciated...You seem to be confusing two things - uniqueidentifer and identity.
NEWID() generates a new uniqueidentifier value; SCOPE_IDENTITY()
returns the last value generated by an IDENTITY column, which is
usually an integer.

I'm guessing (since you haven't provided a CREATE TABLE statement) that
you're using NEWID() as a default on a column? If so, there is no
function to retrieve the new value - typically you would use NEWID() in
your proc to generate the value, then INSERT it; you can then return
the new value as an output parameter (of data type uniqueidentifier,
not integer).

If this isn't helpful, or my guess is wrong, I suggest you post a
CREATE TABLE script for your table, so that it's clear what data types,
constraints etc you have. You should also clarify what you expect to
get back from the procedure.

Simon|||Hi Simon,

I've taken your advice and changed the insert SP as below but I'm still not
getting my GUID back?

Any thoughts..

CREATE PROCEDURE heasvase.[usp_insert_address]

@.ADDR_NAME_2 [char](70) = NULL,
@.ADDR_NO_3 [char](10) = NULL,
@.ADDR_ROAD_4 [char](50) = NULL,
@.ADDR_DISTRICT_5 [char](50) = NULL,
@.ADDR_TOWN_6 [char](50) = NULL,
@.ADDR_BOROUGH_7 [char](50) = NULL,
@.ADDR_PCODE_8 [char](12) = NULL,
@.addr_id [char] OUTPUT

AS

INSERT INTO [HEAPADLive].[dbo].[TBL_ADDR]
(
[ADDR_ID],
[ADDR_NAME],
[ADDR_NO],
[ADDR_ROAD],
[ADDR_DISTRICT],
[ADDR_TOWN],
[ADDR_BOROUGH],
[ADDR_PCODE])

VALUES
(
NEWID(),
@.ADDR_NAME_2,
@.ADDR_NO_3,
@.ADDR_ROAD_4,
@.ADDR_DISTRICT_5,
@.ADDR_TOWN_6,
@.ADDR_BOROUGH_7,
@.ADDR_PCODE_8)

SET @.addr_id = scope_identity()
GO

"Simon Hayes" <sql@.hayes.ch> wrote in message
news:1126687906.495874.71190@.g44g2000cwa.googlegro ups.com...
> You seem to be confusing two things - uniqueidentifer and identity.
> NEWID() generates a new uniqueidentifier value; SCOPE_IDENTITY()
> returns the last value generated by an IDENTITY column, which is
> usually an integer.
> I'm guessing (since you haven't provided a CREATE TABLE statement) that
> you're using NEWID() as a default on a column? If so, there is no
> function to retrieve the new value - typically you would use NEWID() in
> your proc to generate the value, then INSERT it; you can then return
> the new value as an output parameter (of data type uniqueidentifier,
> not integer).
> If this isn't helpful, or my guess is wrong, I suggest you post a
> CREATE TABLE script for your table, so that it's clear what data types,
> constraints etc you have. You should also clarify what you expect to
> get back from the procedure.
> Simon|||Try this:

CREATE PROCEDURE heasvase.[usp_insert_address]
@.ADDR_NAME_2 [char](70) = NULL,
@.ADDR_NO_3 [char](10) = NULL,
@.ADDR_ROAD_4 [char](50) = NULL,
@.ADDR_DISTRICT_5 [char](50) = NULL,
@.ADDR_TOWN_6 [char](50) = NULL,
@.ADDR_BOROUGH_7 [char](50) = NULL,
@.ADDR_PCODE_8 [char](12) = NULL,
@.addr_id uniqueidentifier OUTPUT
AS

set @.addr_id = newid()

INSERT INTO [HEAPADLive].[dbo].[TBL_ADDR]
(
[ADDR_ID],
[ADDR_NAME],
[ADDR_NO],
[ADDR_ROAD],
[ADDR_DISTRICT],
[ADDR_TOWN],
[ADDR_BOROUGH],
[ADDR_PCODE])

VALUES
(
@.addr_id,
@.ADDR_NAME_2,
@.ADDR_NO_3,
@.ADDR_ROAD_4,
@.ADDR_DISTRICT_5,
@.ADDR_TOWN_6,
@.ADDR_BOROUGH_7,
@.ADDR_PCODE_8)
GO

As per my previous post, SCOPE_IDENTITY() has nothing to do with GUIDs
and NEWID(). An IDENTITY column is an auto-incrementing numeric value,
which is usually implemented as an integer, and SCOPE_IDENTITY()
returns the last identity value generated in the current scope.

NEWID() on the other hand generates a binary GUID value of data type
uniqueidentifier. See "IDENTITY (Property)", SCOPE_IDENTITY(),
uniqueidentifier, NEWID() and CREATE TABLE in Books Online for more
information.

By the way, char with no length defaults to char(1), so your @.addr_id
parameter wouldn't work correctly. You can use CAST() if you want to
return the new GUID as a character type.

Simon|||Hi Simon,

Yes I get it now and this work fine. Thank you for sharing your knowledge
and for your patience..

"Simon Hayes" <sql@.hayes.ch> wrote in message
news:1126690720.625513.316760@.g44g2000cwa.googlegr oups.com...
> Try this:
> CREATE PROCEDURE heasvase.[usp_insert_address]
> @.ADDR_NAME_2 [char](70) = NULL,
> @.ADDR_NO_3 [char](10) = NULL,
> @.ADDR_ROAD_4 [char](50) = NULL,
> @.ADDR_DISTRICT_5 [char](50) = NULL,
> @.ADDR_TOWN_6 [char](50) = NULL,
> @.ADDR_BOROUGH_7 [char](50) = NULL,
> @.ADDR_PCODE_8 [char](12) = NULL,
> @.addr_id uniqueidentifier OUTPUT
> AS
> set @.addr_id = newid()
> INSERT INTO [HEAPADLive].[dbo].[TBL_ADDR]
> (
> [ADDR_ID],
> [ADDR_NAME],
> [ADDR_NO],
> [ADDR_ROAD],
> [ADDR_DISTRICT],
> [ADDR_TOWN],
> [ADDR_BOROUGH],
> [ADDR_PCODE])
> VALUES
> (
> @.addr_id,
> @.ADDR_NAME_2,
> @.ADDR_NO_3,
> @.ADDR_ROAD_4,
> @.ADDR_DISTRICT_5,
> @.ADDR_TOWN_6,
> @.ADDR_BOROUGH_7,
> @.ADDR_PCODE_8)
> GO
> As per my previous post, SCOPE_IDENTITY() has nothing to do with GUIDs
> and NEWID(). An IDENTITY column is an auto-incrementing numeric value,
> which is usually implemented as an integer, and SCOPE_IDENTITY()
> returns the last identity value generated in the current scope.
> NEWID() on the other hand generates a binary GUID value of data type
> uniqueidentifier. See "IDENTITY (Property)", SCOPE_IDENTITY(),
> uniqueidentifier, NEWID() and CREATE TABLE in Books Online for more
> information.
> By the way, char with no length defaults to char(1), so your @.addr_id
> parameter wouldn't work correctly. You can use CAST() if you want to
> return the new GUID as a character type.
> Simon

SCOPE_IDENTITY() Help

I was wondering if its possible to use this function if your using aSqlDataReader where I just run a stored procedure that just inserts arow?

Better might be a return value that you get at via a Return Code parameter using ExecuteNonQuery. No reason you could not do a SELECT SCOPE_IDENTITY() at the end of an INSERT SP and then get at it using ExecuteScalar() if you wish.

CREATE PROCEDURE spfoo
@.fooID int
AS
INSERT INTO fooTable(fooID) VALUES(@.fooID)
RETURN SCOPE_IDENTITY()

|||
Hi
Using SQLDataSource and SQL 2005 Stored Procedure I've been successful in creating multiple additional CreateUser fields saving them to "tbl_UserDetails" table.
I pass the UserId to the tbl_UserDetails as well. What I'm struggling with is retreiving the new tbl_UserDetails "Details_Id" - t-sql RETURN SCOPE_IDENTITY()).
I want to integrate it into the Profile data (see Profile creation below in CompleteButton_Click (71)).
I'm not sure if the problem retreiving the Details_Id is in the SQLDSInsert_Inserted (133) code used or if I'm not addressing the retreival in the "correct" stage of "the process". See below.
Thanks
1Imports Telerik.WebControls2Imports SITE.DAL.DBAccess3Imports System.Data4Imports System.Data.SqlClient56PartialClass Site_Pages_Registration7Inherits System.Web.UI.Page8Protected WithEvents Update_DateAs WebControls.HiddenField910Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load11If Session("Record") IsNotNothing Then12 CreateUserWizard1.MoveTo(CompleteWizardStep1)13End If1415 End Sub1617 Protected Sub CreateUserWizard1_CreatedUser(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles CreateUserWizard1.CreatedUser18Dim userAs MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)1920If userIs Nothing Then21 Throw New ApplicationException("Can't find the user.")22 End If2324 Dim DetailsInsert As SqlDataSource = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SQLDSInsert"), SqlDataSource)25 Dim UserId As Guid = DirectCast(user.ProviderUserKey, Guid)26 Session("NewUserId") = UserId27 Dim Details_FirstName As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_FirstName"), TextBox)28 Dim Details_LastName As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_LastName"), TextBox)29 Dim Details_MI As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_MI"), TextBox)30 Dim Details_Title As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Title"), TextBox)31 Dim Details_Company As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Company"), TextBox)32 Dim Details_1Comm As Telerik.WebControls.RadMaskedTextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_1Comm"), Telerik.WebControls.RadMaskedTextBox)33 Dim Details_1CommType As Telerik.WebControls.RadComboBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_1CommType"), Telerik.WebControls.RadComboBox)34 Dim Details_2Comm As Telerik.WebControls.RadMaskedTextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_2Comm"), Telerik.WebControls.RadMaskedTextBox)35 Dim Details_2CommType As Telerik.WebControls.RadComboBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_2CommType"), Telerik.WebControls.RadComboBox)36 Dim Details_Address As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Address"), TextBox)37 Dim Details_City As TextBox = CType(CreateUserWizardStep0.ContentTemplateContainer.FindControl("Details_City"), TextBox)38 Dim Details_State As Telerik.WebControls.RadComboBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_State"), Telerik.WebControls.RadComboBox)39 Dim Details_Zip As Telerik.WebControls.RadMaskedTextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Zip"), Telerik.WebControls.RadMaskedTextBox)40 Dim Details_UserTypeId As Telerik.WebControls.RadComboBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_UserTypeId"), Telerik.WebControls.RadComboBox)41 Dim Details_ReceiveEmail As CheckBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_ReceiveEmail"), CheckBox)4243 DetailsInsert.Insert()4445 Dim UserType As Telerik.WebControls.RadComboBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_UserTypeId"), Telerik.WebControls.RadComboBox)46 Session("UserType") = UserType.SelectedValue.ToString47 End Sub4849 Protected Sub SQLDSInsert_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)50 Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)5152 e.Command.Parameters("@.UserId").Value = user.ProviderUserKey53 e.Command.Parameters("@.Details_FirstName").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_FirstName"), TextBox).Text54 e.Command.Parameters("@.Details_LastName").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_LastName"), TextBox).Text55 e.Command.Parameters("@.Details_MI").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_MI"), TextBox).Text56 e.Command.Parameters("@.Details_Company").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Company"), TextBox).Text57 e.Command.Parameters("@.Details_Title").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Title"), TextBox).Text58 e.Command.Parameters("@.Details_1Comm").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_1Comm"), Telerik.WebControls.RadMaskedTextBox).Text59 e.Command.Parameters("@.Details_1CommType").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_1CommType"), Telerik.WebControls.RadComboBox).SelectedValue60 e.Command.Parameters("@.Details_2Comm").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_2Comm"), Telerik.WebControls.RadMaskedTextBox).Text61 e.Command.Parameters("@.Details_2CommType").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_2CommType"), Telerik.WebControls.RadComboBox).SelectedValue62 e.Command.Parameters("@.Details_Address").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Address"), TextBox).Text63 e.Command.Parameters("@.Details_City").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_City"), TextBox).Text64 e.Command.Parameters("@.Details_State").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_State"), Telerik.WebControls.RadComboBox).SelectedValue65 e.Command.Parameters("@.Details_Zip").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Zip"), Telerik.WebControls.RadMaskedTextBox).Text66 e.Command.Parameters("@.Details_UserTypeId").Value = Int32.Parse(CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_UserTypeId"), Telerik.WebControls.RadComboBox).SelectedValue)67 e.Command.Parameters("@.Details_ReceiveEmail").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_ReceiveEmail"), CheckBox).Checked68 End Sub697071 Protected Sub CompleteButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)72 Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)7374 Dim pb As ProfileBase = ProfileBase.Create(user.UserName)75 pb.SetPropertyValue("FirstName", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_FirstName"), TextBox).Text)76 pb.SetPropertyValue("LastName", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_LastName"), TextBox).Text)77 pb.SetPropertyValue("UserName", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"), TextBox).Text)78 pb.SetPropertyValue("Record", Session("Record"))79 pb.SetPropertyValue("Company", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Company"), TextBox).Text)80 pb.SetPropertyValue("Title", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Title"), TextBox).Text)81 pb.SetPropertyValue("Comm1", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_1Comm"), Telerik.WebControls.RadMaskedTextBox).Text)82 pb.SetPropertyValue("Comm1Type", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_1CommType"), Telerik.WebControls.RadComboBox).SelectedValue)83 pb.SetPropertyValue("Comm2", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_2Comm"), Telerik.WebControls.RadMaskedTextBox).Text)84 pb.SetPropertyValue("Comm2Type", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_2CommType"), Telerik.WebControls.RadComboBox).SelectedValue)85 pb.SetPropertyValue("Address", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Address"), TextBox).Text)86 pb.SetPropertyValue("City", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_City"), TextBox).Text)87 pb.SetPropertyValue("State", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_State"), Telerik.WebControls.RadComboBox).SelectedValue)88 pb.SetPropertyValue("Zip", CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Zip"), Telerik.WebControls.RadMaskedTextBox).Text)8990 pb.Save()9192 Dim lblRegisterCompleteName As Label = CreateUserWizard1.CompleteStep.FindControl("lblRegisterCompleteName"), Label93 lblRegisterCompleteName.Text = Profile.FirstName & " " & Profile.LastName94 Dim Muser As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)95 If Muser Is Nothing Then96 Throw New ApplicationException("Can't find the user.")97End If98 Muser.IsApproved =False99 End Sub100101 Protected Sub btnTeamProfile_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)102Dim userAs MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)103104Dim pbAs ProfileBase = ProfileBase.Create(user.UserName)105 pb.SetPropertyValue("FirstName",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_FirstName"), TextBox).Text)106 pb.SetPropertyValue("LastName",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_LastName"), TextBox).Text)107 pb.SetPropertyValue("UserName",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"), TextBox).Text)108 pb.SetPropertyValue("Record", Session("Record"))109 pb.SetPropertyValue("Company",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Company"), TextBox).Text)110 pb.SetPropertyValue("Title",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Title"), TextBox).Text)111 pb.SetPropertyValue("Comm1",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_1Comm"), Telerik.WebControls.RadMaskedTextBox).Text)112 pb.SetPropertyValue("Comm1Type",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_1CommType"), Telerik.WebControls.RadComboBox).SelectedValue)113 pb.SetPropertyValue("Comm2",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_2Comm"), Telerik.WebControls.RadMaskedTextBox).Text)114 pb.SetPropertyValue("Comm2Type",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_2CommType"), Telerik.WebControls.RadComboBox).SelectedValue)115 pb.SetPropertyValue("Address",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Address"), TextBox).Text)116 pb.SetPropertyValue("City",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_City"), TextBox).Text)117 pb.SetPropertyValue("State",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_State"), Telerik.WebControls.RadComboBox).SelectedValue)118 pb.SetPropertyValue("Zip",CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Details_Zip"), Telerik.WebControls.RadMaskedTextBox).Text)119120 pb.Save()121 Response.Redirect("Profile.aspx")122End Sub123124 Protected Sub CompleteWizardStep1_PreRender(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles CompleteWizardStep1.PreRender125Dim btnTeamProfileAs Button =CType(CompleteWizardStep1.ContentTemplateContainer.FindControl("btnTeamProfile"), Button)126If Session("UserType") ="2"Then127 btnTeamProfile.Visible =True128 Else129 btnTeamProfile.Visible =False130 End If131 End Sub132133 Protected Sub SQLDSInsert_Inserted(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)134Dim DetailsInsertAs SqlDataSource =CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SQLDSInsert"), SqlDataSource)135Dim RecordAs Integer = DetailsInsert.InsertParameters.Add("@.Details_Id", System.Data.ParameterDirection.ReturnValue)136'Dim Record As Integer = e.Command.ExecuteScalar137 Session("Record") = Record.ToString138139 Response.Redirect("Registration.aspx")140End Sub141142143End Class144

SCOPE_IDENTITY()

Hello altogether, my problem ist that I get following error message:

Create Stored Procedure
Unable to chances to the stored procedure.
Error Details:
'Scope_Identity' is not a recognized function name.

This is my Stored Procedure:

CREATE PROCEDURE sp_HyperSoftCustomer
@.Name varchar(25),
@.Adress varchar(250)
as
insert into HyperSoftCustomer(Name, Adress, Date)
values (@.Name, @.Adress, GetDate())
Select SCOPE_IDENTITY()
GO

I am using MSDE - MSSQLServer

I hope there is anybody who can help me?

Thanks, mexx

Hmmmm, that works fine for me. Are you using MSDE 2000?|||

Hi, I am working with

SQL Distributed Management Framework (SQL-DMF)
Microsoft Server Service Manager
Version 7.00.623

My System is Windows Home Edition and I simulate the Internet Information Services IIS (from Windows Professionel Edition) with the Web Matrix Webserver.

Is something missed? Is there a problem of the configuration?

Regards, mexx

|||

mexx:

Hi, I am working with

SQL Distributed Management Framework (SQL-DMF)
Microsoft Server Service Manager
Version 7.00.623


Accoring toHow to identify your SQL Server version, you are running a version of SQL Server 7. MSDE 1.0 runs on the SQL Server 7 engine. SCOPE_IDENTITY was not available in this version; use @.@.IDENTITY instead.

I suggest you install MSDE 2000, which uses the SQL Server 2000 engine. You can get it from here: Installing MSDE for ASP.NET Web Matrix.

Scope_identity equal to 0 from a stored proc as we

Here is my stored proc: InsertAccount

Create PROCEDURE dbo.InsertAccount
@.AccRisAsse bit,
@.AccHldBll bit,
@.Acctaxexm bit
AS
insert into TblAccount(AccRisAsse,AccHldBll,Acctaxexm)
values(@.AccRisAsse,@.AccHldBll,@.Acctaxexm)

return scope_identity()

GO

And here is the code in .Net to run the proc and get back the scope_identity:

I delcare my sqlCommand sqlcmdInsNeAcc and connection fromsystem.data.Sqlclient, I open my connection. all goes well then I do:
sqlcmdInsNeAcc.type=commandtype.storedprocedure
sqlcmdInsNeAcc.CommandText = "InsertAccount"
pm =sqlcmdInsNeAcc.Parameters.Add(New SqlParameter("@.AccountNumber",SqlDbType.BigInt))
pm.Direction = ParameterDirection.ReturnValue
Dim kAccountNumber as integer
kAccountNumber = sqlcmdInsNeAcc.Parameters("@.AccountNumber").Value

pm =sqlcmdInsNeAcc.Parameters.Add(New SqlParameter("@.AccRisAsse",SqlDbType.Bit))
pm.Value = myvalue1
pm =sqlcmdInsNeAcc.Parameters.Add(New SqlParameter("@.AccHldBll",SqlDbType.Bit))
pm.Value = myvalue2
pm =sqlcmdInsNeAcc.Parameters.Add(New SqlParameter("@.Acctaxexm",SqlDbType.Bit))
pm.Value = myvalue3

sqlcmdInsNeAcc.executenonquery

then when I try to display the value of my returned scope identity from the variable: kAccountNumber
ALL I GET IS ZERO although my row is created in the table with the right Account number

Thanks

you should move

kAccountNumber = sqlcmdInsNeAcc.Parameters("@.AccountNumber").Value

to blow the

sqlcmdInsNeAcc.executenonquery

Hope this help

|||that helped perfectly. am thankful