I am trying to create stored procedure i Query analyzer in visual studio 2005. I am having
difficulty though. Whenever I press the execute button, here is the error message I get:
Msg 102, Level 15, State 1, Procedure MarketCreate, Line 21
Incorrect syntax near 'MarketName'.
Here is the stored procedure. Note that the very first column in named "MarketId" but I did not
include it in the stored procedure since it should be auto generated.
USE [StockWatch]
GO
/****** Object: StoredProcedure [dbo].[MarketCreate] Script Date: 08/28/2007 15:49:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
I setup the databse and Visual Web Developer to use stored procedures when the insert command is used. The database also uses the field UserName that I pass using a SessionParameter within the InserParameter block from the Membership.GetUser.Username from the aspnet_ tables.
My difficulty is when using the "Formview" as the body to with which to insert (I wanted the design versatility of FormView) I get an error: "system.formatExpression: Input string was not in a correct format" when I leave the textboxes empty and invoke the insert command. I first assumed that the bound textboxes are not being converted correctly when left blank, so I used the ConvertEmptyStringToNull=True, with no success. I then coupled that with the Type=[correct format] still with the same error. Alas, my final attempt was to set defaults in the "ALTER PROCEDURE" within the stored procedure itself.
Is it possible to create a stored procedure that execute a delete command from a table whose name is specified as a parameter of the stored procedure?Thank you
ALTER PROCEDURE companyinsert@companyid INT IDENTITY(1,1) NOT NULL,@companyname varchar(20),@address1 varchar(30)ASINSERT INTO companymaster ( companyname, address1)VALUES (@companyname,@address1)i don't want the companyname having the same names are recorded again with the different company id..Can anyone help me and modify my code according it's giving error...in the @companyid.It is being done in sql server 2005 with asp.net C# 2005
I have some script for creating the table i want but i need some help creating a Stored Procedure. That will Insert the UserId from the aspnet_Users Table (UserId) into the UserId Column in my table. So when a user creates an account it will put that users id into my table. The data will be retrieved by a FormView and the user can Update their info threw the FormView control.. I just need to associate the UserId from the aspnet_User Table with my table, so the data is stored per UserId in a new row for each new user..create table dbo.custom_Profile ( UserId uniqueidentifier not null Primary Key, IamWeAre nvarchar(50) null, InterestedIn nvarchar(256) null, IntroTitle nvarchar(100) null, TellOthers nvarchar(MAX)null, MaritalStatus nvarchar(20) null, BodyType nvarchar(50) null, Race nvarchar(20) null, Smoking nvarchar(20) null, Drinking nvarchar(20) null, Drugs nvarchar(20) null, Education nvarchar(256) null)
I have a table (displayed in a gridview) of services we provide. I have another table (the logfile) that displays the current status of those services. This GridView displays the service and current status.When a new service is created there is obviously no status yet. This causes a problem because my stored procedure (below) does not display that new service in my GridView. How can I ensure EVERY service is included in my dataset regardless of whether or there is a status? (and how can I get away from having to group by all the time?) select s.servicename, s.opr, c.commentid,c.comment, c.etic, t.statusfrom svc_service sinner join svc_comment c on c.serviceid = s.serviceidinner join svc_status t on t.statusid = c.statusidgroup by s.servicename, s.opr, c.commentid, c.comment, c.etic, t.status TIA, Jon
I have an inline sql query which i want to convert to a stored procedure. The query is simplified as follows:
string sql = "SELECT * FROM property_property WHERE Location = " + location; if(state != null) sql += " AND State = " + state; if(cost !=null) sql += " AND Cost = " + cost;
The query is created depending on variable states; there are 7 in the real one which together creates the required query to query the database. Im not sure how/if it can be converted in to a stored proc
I know some of the basics and managed to convert every other query except this.
I already know how you create a stored procedure to add information to a database or retrieve a value for one record. But I don't know how to create a stored procedure that will retrieve many records for a certain querystring value. Here's my simple stored procedure to show one record: CREATE PROCEDURE DisplayCity(@CityID int)AS SELECT City From City where CityID = @CityIDGO My code for displaying the City: Sub ShowCity() Dim strConnect As String Dim objConnect As SqlConnection Dim objCommand As New SqlCommand Dim strCityID As String Dim City As String
'Get connection string from Web.Config strConnect = ConfigurationSettings.AppSettings("ConnectionString") objConnect = New SqlConnection(strConnect)
objConnect.Open()
'Get incoming City ID strCityID = request.params("CityID")
'Display SubCategory City = "" & objcommand.ExecuteScalar().ToString() lblCity.Text = City
lblChosenCity.Text = City
objConnect.Close()
End Sub
Here's the code I'd like to get help with changing into a stored procedure: Sub BindDataList()
Dim strConnect As String Dim objConnect As New System.Data.SqlClient.SQLConnection Dim objCommand As New System.Data.SqlClient.SQLCommand Dim strSQL As String Dim dtaAdvertiser As New System.Data.SqlClient.SQLDataAdapter() Dim dtsAdvertiser As New DataSet() Dim strCatID As String Dim strCityID As String Dim SubCategory As String Dim SubCategoryID As String Dim BusinessName As String Dim City As String
'Get connection string from Web.Config strConnect = ConfigurationSettings.AppSettings("ConnectionString")
objConnect = New System.Data.SqlClient.SQLConnection(strConnect)
'Create a new DataAdapter object dtaAdvertiser.SelectCommand = objCommand
'Get the data from the database and 'put it into a DataTable object named dttAdvertiser in the DataSet object dtaAdvertiser.Fill(dtsAdvertiser, "dttAdvertiser")
'If no records were found in the category, 'display that message and don't bind the DataGrid if dtsAdvertiser.Tables("dttAdvertiser").Rows.Count = 0 then
lblNoItemsFound.Visible = True lblNoItemsFound.Text = "Sorry, no listings were found!"
else
'Set the DataSource property of the DataGrid dtlAdvertiser.DataSource = dtsAdvertiser
'Set module level variable for page title display BusinessName = dtsAdvertiser.Tables(0).Rows(0).Item("BusinessName") SubCategory = dtsAdvertiser.Tables(0).Rows(0).Item("SubCategory") SubCategoryID = dtsAdvertiser.Tables(0).Rows(0).Item("SubCategoryID") City = dtsAdvertiser.Tables(0).Rows(0).Item("City")
'Bind all the controls on the page dtlAdvertiser.DataBind()
end if
objCommand.ExecuteNonQuery()
'this is the way to close commands objCommand.Connection.Close()
I need to add up the number of people who joined this month and compare that number to the number of people who joined last month and display the results in a report and I have never done a stored procedure and I was wondering if it would be ease to do?
FirstName..LastName.....StartedDate Randy......Simpson......5/4/2007 10:00:00 PM Steve......Rowe.........5/2/2007 10:00:00 PM Eric.......Dickerson....5/4/2007 10:00:00 PM Gloria.....Sanches......5/1/2007 12:00:29 AM Andres.....Marcelino....5/1/2007 12:06:31 AM katie......ryan.........6/4/2007 12:08:35 AM Denise.....River........6/4/2007 12:27:14 AM Kellog.....Stover.......6/5/2007 12:37:20 AM Glenn......Sanders......6/1/2007 12:42:40 AM
Im trying to create a stored procedure that selects everything from afunction name that im passing in through a parameter..create procedure SP_selectall(@functionname varchar(25))asselect * from @functionamegoI keep getting this error:Server: Msg 137, Level 15, State 2, Procedure SP_selectall, Line 5Must declare the variable '@functioname'.Whats the issue?
Want help in creating the stored procedure of company where id is the PrimaryKey in the table companymaster which is created in sql server 2005.1 ALTER PROCEDURE companyinsert 2 3 @companyid int, 4 @companyname varchar(20), 5 @address1 varchar(30) 6 7 AS 8 9 INSERT INTO companymaster 10 ( companyname, address1) 11 VALUES (@companyname,@address1) Procedure or Function 'companyinsert' expects parameter '@companyid', which was not supplied.
The id is to be created autogenerate in the sequence number.There should be no duplicated companyname with different ids in same table.Apart from the above error can anyone pls give me or tell me the code or modify the stored procedure according to the above..thanxs....
I was trying to create a new stored procedure. It's pretty straight forward using Insert Into. Here's what I wrote: CREATE PROCEDURE dbo.InsertPicks@ID varchar,@Race int,@P1 varchar,@P2 varchar,@P3 varchar,@P4 varchar,@P5 varchar,@P6 varchar,@P7 varchar,@P8 varchar,@P9 varchar,@P10 varchar, INSERT INTO tblPicks(pRace, pPlayer, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)VALUES(@Race,@ID,@P1,@P2,@P3,@P4,@P5,@P6,@P7,@P8,@P9,@P10) RETURN I first wrote the T-SQL code myself, but when I opened the Query Builder so I could validate it and check it. It validated and when I executed it, it worked great and inserted a new record into the table. Yet, when I closed the Query Builder, and tried to save the Stored Procedure (which I assume is how you create it) I get an error that there is a Incorrect Syntax near "Insert". I see nothing wrong with the syntax, and it worked fine in the Query Builder. What am I doing wrong? Thanks, Bob
Is there a way I can use one SQL server 2005 (full edition not express) Stored procedure that can execute a .SQL file as if it were in the SQL management studio Query window? I have the situation where I have some .SQL file which were created with the 'Create to File' option in SQL Management studio. I then want to send them to a user who can execute them to create a SP on his SQL server without having to run the SQL management tools. Regards Clive
I am using SQL Server Express within visual studio and am needing to create a stored procedure. The proble is that every time I finish and close it then it asks me if I want to save the changes which of course I want to. But then it always comes up with a message box that says "invalid object name" followed with the name of the stored procedure. ??? why? I try creating a stored procedure from scratch or copying the code of another stored procedure. It alway gives me that message and does not let me save the stored procedure. I tried changing the default name of "dbo.storedprocedure1" or even leaving it as is and always I get the message that says "invalid object name: dbo.storedprocedure1" and it does not let me save the procedure. What am I doing wrong?
--Drop procedures if they exsit if exists (SELECT * FROM master.dbo.sysobjects WHERE id = object_id(N'[dbo].[sp_PagedItems]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sp_PagedItems] GO
if exists (SELECT * FROM master.dbo.sysobjects WHERE id = object_id(N'[dbo].[sp_PagedItemsByTime]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[sp_PagedItemsByTime] GO
if exists (SELECT * FROM master.dbo.sysobjects WHERE id = object_id(N'[dbo].[sp_selectedEventMessage]') AND OBJECTPROPERTY(id,N'IsProcedure')=1) drop procedure [dbo].[sp_selectedEventMessage] GO
--Definitions of procedures USE LanDeskDB GO
CREATE PROCEDURE sp_PagedItems ( @QueryVARCHAR(1000), @Pageint, @RecsPerPageint, @startDateVARCHAR(100), @endDateVARCHAR(100), @allTimeint, @flagint ) AS BEGIN SET NOCOUNT ON DECLARE @SQL VARCHAR(2000) DECLARE @Order VARCHAR(200) DECLARE @TotalBIGINT
CREATE TABLE #TempTable ( TempTableID BIGINT NOT NULL PRIMARY KEY IDENTITY(1,1), EventLogID BIGINT , EventDateTime datetime, MachineID INT , TypeID INT , SessionID INT , SourceID INT , MessageID BIGINT , UserID INT, CategoryNumber INT, EventID INT ) IF (@flag = 1) BEGIN SET @Order = 'ORDER BY EventDateTime' END IF (@flag = 2) BEGIN SET @Order = 'ORDER BY SessionID,EventDateTime' END IF (@flag = 3) BEGIN SET @Order = 'ORDER BY TypeID,EventDateTime' END IF (@flag = 4) BEGIN SET @Order = 'ORDER BY CategoryNumber,EventDateTime' END IF(@allTime <> 1) BEGIN IF(LEN(@Query)>1) BEGIN SET @Query = @Query+'AND EventDateTime>='''+@startDate+''' AND EventDateTime <= '''+@endDate+'''' END ELSE BEGIN SET @Query = 'WHERE EventDateTime>='''+@startDate+''' AND EventDateTime <= '''+@endDate+'''' END END SET @SQL= 'INSERT INTO #TempTable (EventLogID,EventDateTime,MachineID,TypeID,SessionID,SourceID,MessageID,UserID,CategoryNumber,EventID)'+ 'SELECT EventlogID,EventDateTime,MachineID,TypeID,SessionID,SourceID,MessageID,UserID,CategoryNumber,EventID FROM EventLog '+ @Query+' '+@Order EXEC (@SQL)
CREATE TABLE #TempTableTwo ( TempTableTwoID BIGINT NOT NULL PRIMARY KEY IDENTITY(1,1), TempTableID BIGINT, EventLogID BIGINT , EventDateTime datetime, MachineID INT , TypeID INT , SessionID INT , SourceID INT , MessageID BIGINT , UserID INT, CategoryNumber INT, EventID INT, )
SELECT * FROM #TempTable T WHERE T.TempTableID >@FirstRec AND T.TempTableID < @LastRec
SELECT TempT.EventLogID AS EventLogID,TempT.EventDateTime AS EventDateTime, Ma.MachineName AS MachineName,Se.SessionName AS SessionName,Ty.TypeName AS TypeName, TempT.CategoryNumber AS CategoryNumber,Us.UserName AS UserName,So.SourceName AS SourceName, TempT.EventID AS EventID FROM #TempTableTwo TempT,Machines Ma,Types Ty,Sessions Se,Sources So,Users Us WHERE TempT.MachineID = Ma.MachineID AND TempT.TypeID = Ty.TypeID AND TempT.SessionID = Se.SessionID AND TempT.SourceID = So.SourceID AND TempT.UserID = Us.UserID
SELECT COUNT(*) FROM #TempTable
DROP TABLE #TempTable DROP TABLE #TempTableTwo SET NOCOUNT OFF END GO
CREATE PROCEDURE sp_PagedItemsByTime ( @QueryVARCHAR(1000), @Page int, @RecsPerPage int, @startDateVARCHAR(100), @endDateVARCHAR(100), @allTime int ) AS BEGIN EXEC sp_PagedItems @Query,@Page,@RecsPerPage,@startDate,@endDate,@allTime,1 END GO
CREATE PROCEDURE sp_selectedEventMessage ( @EventLogID int ) AS
BEGIN
SELECT Ma.MachineName,Ev.EventDateTime,Se.SessionName,Ty.TypeName,So.SourceName,Me.MessageDescription FROM EventLog Ev,Sessions Se,Types Ty,Sources So,Messages Me,Machines Ma WHERE Ev.EventLogID = @EventLogID AND Ev.SessionID = Se.SessionID AND Ma.MachineID = Ev.MachineID AND Ev.TypeID = Ty.TypeID AND Ev.SourceID = So.SourceID AND Ev.MessageID = Me.MessageID
END
GO
I got the error messge as Server: Msg 2714, Level 16, State 5, Procedure sp_PagedItems, Line 107 There is already an object named 'sp_PagedItems' in the database. Server: Msg 2714, Level 16, State 5, Procedure sp_PagedItemsByTime, Line 13 There is already an object named 'sp_PagedItemsByTime' in the database. Server: Msg 2714, Level 16, State 5, Procedure sp_selectedEventMessage, Line 12 There is already an object named 'sp_selectedEventMessage' in the database.
But I already delete those procedures before I create them. Could anyone give some suggestion?
Can I create system stored procedure in sql 7.0? After I used 'alter' to modify a system sp, it's category change from 'system' to 'user'. Is there way to change it back? Thanks a lot!
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 GO
Im trying to create a view from within a stored procedure and are having problems. Is it possible to do this? And if so, how? I've been trying with the code below.
CREATE PROC upProcName AS
DECLARE @Variable varchar(50)
CREATE VIEW vwName AS
SELECT DISTINCT Table1.*, Table2.* FROM dbo.Table1 INNER JOIN dbo.Table2 AS BUG ON Table1.Col1 = Table2.Col1 WHERE LI.accname = @Variable
From within a stored procedure in an existing database I'm creating a new database from the scratch.
In the query window if I write the statement: CREATE DATABASE [tomasdb]
USE [tomasdb] GO CREATE PROCEDURE TEST1 AS BEGIN DECLARE @something varchar(12) set @something = '123' END
everything works ok and the database is created and the stored procedure Test1 is created within it. However, if I want to do the same from another stored procedure (in another database), i.e. I write
EXEC(' CREATE DATABASE [tomasdb] USE [tomasdb] CREATE PROCEDURE TEST1 AS BEGIN DECLARE @something varchar(12) set @something = ''123'' END ')
the problem I get is that I'm not allowed to put USE to change the execution context into [tomasdb] before the CREATE PROCEDURE statement. My question is: how can I change the context in this situation / or / can I create the stored procedure in the [tomasdb] database somehow from outside (another context).
Hi guys!i want to create one cursor in the t-sql. the problem is i want to usestored procedure instead of select command in cursor.can anyone tell me how can i use stored procedure's o/p to createcursor?i'm using sql 2000 and .net 2.0thanks,Lucky
HelloNewbie here.Is there a way of creating a VIEW...using a stored procedure. I ambasically trying to create a view to return some data that I amgetting using a stored procedure.I have created the procedure and when I execute this its working ok.The stored procedure uses a datefrom and dateTo which I have set up bytweaking the getdate() and getdate()-2.In other words can you create a view like thisCREATE VIEW view_testASexec proc_testGOAny help will be greatly appreciated.Remmy
Hi all,Sorry for HTML, there is a lot of code & comments I tried to create a stored procedure from 3 queries .. to reduce # of times DB gets access from 1 asp page. The result procedure only works 1/2 way (does return the rest of the SELECT statement) :( Please help me figure out what stops it mid way? I need it to return all the results from the SELECT statements AND the number of rows (ScriptsNo) from the count(*): Here is my stored procedure:CREATE PROCEDURE csp_AuthorAccountInfo@CandidateID int,AS DECLARE @ScriptsNo int, @ManuscriptID int SELECT count(*) as ScriptsNo FROM Manuscripts WITH (NOLOCK) WHERE CandidateID = @CandidateID/* this is where it stops all the time :(Theoretically speaking, next SELECT will only return 1 row with Candidate's info*/SELECT c.*, l.LocationID, @ManuscriptID=m.ManuscriptID, l.State, cn.Country FROM Candidates c INNER JOINManuscripts m ONc.CandidateID = m.CandidateID INNER JOINLocations l ON c.LocationID = l.LocationID INNER JOINcn ON l.CountryCode = cn.CountryCodeWHERE c.CandidateID = @CandidateID/* next SELECT should normally return manu rows with Candidate's submitted manuscripts */SELECT m.ManuscriptID, m.IsReceived, msn.StageName, ms.DatePosted, ns.CommentsFROM Manuscripts m INNER JOINManuscriptStages ms ON m.ManuscriptID = ms.ManuscriptID INNER JOINManuscriptStageNames msn ON ms.StageNameID = msn.StageNameIDWHERE m.ManuscriptID = @ManuscriptIDORDER BY ms.DatePosted DESCGO
Hi,I'm trying to work around a bug that our helpdesk software has. When a newissue is created, it cannot automatically default 2 fields to the value ofNo like we need it to.I have a field called "Audited" and one called "Billed to Client". When anew issue is openned, it just leaves the value as Null in the databaseinstead of a value of No.I would like to create a stored procedure and schedule it to run every 10minutes to change any value of Null in those columns to No.Database: bridgetrakTable: IssuesColumn: AuditedColumn: BilledIf someone could help me out that would be great! I just don't have verymuch experience with SQL statements.Please email me at Join Bytes!Thanks,Shawn
I have been using SQL Server 2000 and creating Stored Procedure. I need these Stored Procedure to create Reports in Crystal Reports. In SQL Server 2000: it is very simple to create a stored procedure: Go to Enterprise Manager->Databases-> Choose a database-> stored procedure->New-> Simply Add to the following syntax: CREATE PROCEDURE [OWNER].[PROCEDURE NAME] AS GO My problem is that it is More Complex to use Stored Procedure In SQL Server 2005: the stored procedure is under Databases->choose a database->programmability->create new stored procedure: But how can I use it: I need your help It is more complex than the Stored Procedure in SQL Server 2000 Thank you Your help is highly appreciated
I'm not sure if this is possible, i want to create a report from a stored procedure, all the stored procedure does is select data from my database, however, the code is 1800+ lines of code, it executes in about 1 minute, which is fine. My problem is that i can't paste 1800+ lines of code into the dataset in Reporting Services, so is it possible to get the values from my stored procedure into reporting services so that i can use them to design and execute my report?
Or musst i find an alternative way to do this?
Any help or suggestions will be greatly appreaciated and welcome.
I create StringBuilder type forconcating string to create a lot of stored procedure at once However When I use this command BEGIN TRANSACTIONBEGIN TRY--////////////////////// SQL COMMAND ///////////////////////// -------------------- This any command --/////////////////////////////////////////////////////////// --COMMIT TRANEND TRYBEGIN CATCH IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;END CATCHIF @@TRANCOUNT > 0 COMMIT TRANSACTION; on any command If I use Create a lot of Tablessuch as BEGIN TRANSACTION BEGIN TRY --////////////////////// SQL COMMAND /////////////////////////CREATE TABLE [dbo].[Table1]( Column1 Int , Column2 varchar(50) NULL ) ON [PRIMARY]CREATE TABLE [dbo].[Table2]( Column1 Int , Column2 varchar(50) NULL ) ON [PRIMARY] CREATE TABLE [dbo].[Table3](
Column1 Int ,
Column2 varchar(50) NULL
) ON [PRIMARY] --/////////////////////////////////////////////////////////// --COMMIT TRAN END TRY
BEGIN CATCH IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION; END CATCH
IF @@TRANCOUNT > 0 COMMIT TRANSACTION; It correctly works. But if I need create a lot of Stored procedure as the following code : BEGIN TRANSACTION BEGIN TRY --////////////////////// SQL COMMAND ///////////////////////// CREATE PROCEDURE [dbo].[DeleteItem1] @ProcId Int, @RowVersion Int AS BEGIN DELETE FROM [dbo].[ItemProcurement] WHERE [ProcId] = @ProcId AND [RowVersion] = @RowVersion END CREATE PROCEDURE [dbo].[DeleteItem2]
@ProcId Int
AS
BEGIN
DELETE FROM [dbo].[ItemProcurement]
WHERE
[ProcId] = @ProcId
END CREATE PROCEDURE [dbo].[DeleteItem3]
@ProcId Int
AS
BEGIN
DELETE FROM [dbo].[ItemProcurement]
WHERE
[ProcId] = @ProcId
END
--/////////////////////////////////////////////////////////// --COMMIT TRAN END TRY
BEGIN CATCH IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION; END CATCH
IF @@TRANCOUNT > 0 COMMIT TRANSACTION; It occurs Error ????? Please help me How should I solve them ?
I am using vwde2008 and created db and table. i want to create a stored procedure that will insert values. I am bit lost on how write this. this is my table info table = BusinessInfo Columns = BusinessID, BusinessName, BusinessAddress how can i create a stored procedure ?
Hello all, I am having a lot of trouble with stored procedures. Could anyone help me out. I have a table which contains a number of meetings. What I want to do is search this table, get out all the meetings for today and put them in a seperate table meetings today. I can select the values, and I can insert the values. But how do I store the values so that i can pass the results of the select to the insert? Im also having a lot of trouble with storing date values. ANy help would be greatly appreciated. Regards, Padraic Hickey
I'm trying to put scripts to create our stored procedures under version control.
However I don't want these scripts to be run if the stored procedure already exists (we'll be using update scripts to alter existing stored procedure I think).
Anyway I tried :
Code:
SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO
/****** Object: Stored Procedure dbo.getEnglandHotelsByATOPResort Script Date: 26/10/2005 10:40:01 ******/ if NOT EXISTS (SELECT object_id('procedureName','p')) CREATE PROCEDURE [dbo].[procedureName] @location char(2) AS ...Procedure...
GO
SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO
I know that the if NOT EXISTS ... part works as doing the following returns the expected result :
Code:
IF NOT EXISTS (SELECT object_id('procedureName','p')) SELECT 'FALSE' ELSE SELECT 'TRUE'
However when trying to do this before the CREATE PROCEDURE I get :
Server: Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'PROCEDURE'. Server: Msg 137, Level 15, State 1, Line 12 Must declare the variable '@location'.
Is it possible to create an event handler in a VB.net application to run whenever a Stored Procedure is run.
My application has a scheduled task which is created and scheduled by users of the application, whenever this scheduled task is run I would like it to contact the application to kick off a sequence of tasks. I would appreciate if anybody could point me in the right direction.
I am a fairly experienced programmer, but new to SQL Server - I understand basic DB theory well enough, but don't have much practical experience with using SQL Server.
I'm working on a project at the moment, where, as part of the spec, users can create 'systems' in the database. For example, in a parts database for a pumping station, there may be 10,000 parts. Rather than have one huge database for, say, 10 pumping stations, we would prefer to have 10 smaller databases, each dedicated to its own system. The schemas would be identical.
I think one approach to this would be have an empty database in SQL server (with the correct tables/schemas/relationships etc) and then copy that within SQL server, with a new name (the system name), probably using a stored procedure.
My question: Is this possible, is there already a stored procedure in SQL Server (2000) to do this, or do I have to write one? Writing a SP to physically create the database from scratch would be a nightmare, I'm hoping there is a simple 'copy_db to new_db' type stored procedure. Maybe there is a program can read a DB and create a script to re-create the DB under a new name?