Tell Me How To Write A Nested Procedure

Jan 14, 2008

Hi,
Please tell me how can i write a stored procedure inside another stored procedure.

With Regards,
litu

litu

View 1 Replies


ADVERTISEMENT

Tell Me How To Write A Nested Procedure

Jan 14, 2008

Hi,
Please tell me how can i write a stored procedure inside another stored procedure.

With Regards,
litu

litu

View 2 Replies View Related

How To Write A Nested GROUP BY Query, Please Help.

Jun 6, 2004

Use Pubs
SELECT pub_id, type, SUM(price) as Total_price
FROM titles
GROUP BY pub_id, type

The above query returns the following resultset:


0736business 2.9900
1389business 51.9300
0877mod_cook 22.9800
1389popular_comp42.9500
0736psychology 45.9300
0877psychology 21.5900
0877trad_cook 47.8900
0877UNDECIDED NULL


Now I want to add another "Group By" on type, so I tried:

Select type, sum(Total_Price) from
(SELECT pub_id, type, SUM(price) as Total_Price
FROM titles
GROUP BY pub_id, type)
Group By type

But I got error: Incorrect syntax near the keyword 'Group'. How can I write such a nested group by query.

Thanks in advance for any help.

View 5 Replies View Related

Calling A Nested Procedure

Sep 11, 2006

Everytime I execute this script - I am not getting the result I want.  I was hoping to take the some parameters call one stored procedufre with in the main procedure.  I was hoping to assign a variable to the nested  procedure and use that variable in the main procedure, but I am getting a '0' as result - however when I call the a inner procedure by itself if get the correct result.  Can someone look at this and tell me where I am wrong?  It seems to be a scope problem. Thanks set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGO-- =============================================-- Author:        -- Create date: September 8,2006-- Description:    Inserts a new project-- =============================================ALTER PROCEDURE [echo88].[insertProject]     -- Add the parameters for the stored procedure here    @name varchar(50),     @desc varchar(MAX),    @start datetime,    @finish datetime,    @memid int,    @addr1 varchar(32),    @addr2 varchar(16),    @city varchar(32),    @stateid int,    @zipcode char(5)ASBEGIN        -- SET NOCOUNT ON added to prevent extra result sets from    -- interfering with SELECT statements.    SET NOCOUNT ON;    DECLARE @siteid int;    EXEC @siteid = insertSite @addr1, @addr2, @city, @stateid, @zipcode;    -- Insert statements for procedure here    INSERT INTO Project(Title, Description, Start, Finish, SiteID, MemberID ) VALUES ( @name, @desc, @start, @finish, @siteid, @memid );END

View 1 Replies View Related

Nested Stored Procedure

Jul 13, 2005

Hi, I have two tables:TABLE 1                        Table 2==========              ==========UID                                  TeamNameTeamID <------------------> TeamID      and I am trying to obtain the value of TeamName via a nested stored procedure. However, I am only allowed to obtain the @UID as input parameter. I tried writing the following:Select    table2.TeamNameFrom       Table1, Table2Where    (table1.TeamID=table2.TeamID) and (UID = @ UID)It seems to not work as TeamID was not given. Thus, my other idea of doing this is to:1) Execute a sql to first obtain the TeamID value with the @UID parameter given.then 2)Execute another sql to obtain the TeamName with the result from the first sql as the input parameter.However, I have never worked with nested sql, so it would be great if someone can link me a site that they know. Better yet, write me an example code.Thanks you very much!

View 3 Replies View Related

Nested Stored Procedure (help)

Jan 31, 2002

Is there a way I can do this? If this statement is true I would like for it to do the update stmt otherwiste do the insert stmt. The code shown below has syntax errors. Any help would be greatly appreciated.

IF (SELECT number, serial
FROM serial
WHERE number = @number and serial is null)

BEGIN

Update Statement

END

ELSE

BEGIN
Insert Statement


END

View 1 Replies View Related

Nested Stored Procedure

Jun 12, 2001

I have one View say V1 and a Table T1
the Structure is say V1 (a,b,a,d) 4 fields
T1 has (e,f,g,h,i,j ) 6 fields

I want to loop through The V1 view and for each record in the View, after
doing some checks i want to insert a record in the T1 table...
using stored procedures, as there could be thousands of records

Something like this

V1 = Select * from V1
While not V1.EOF

Insert into T1

Wend

View 2 Replies View Related

Nested Stored Procedure?

Mar 8, 2005

I have a stored procedure that returns a list of userIds that are available to the logged in user. I need to be able to use this list of userIds in another stored procedure whose purpose is to simply query a table for all results containing any of those userIds. So if my first Stored Procedure returns this: 2 3 5 6 I need my select statement to do something like this: select UserId, Column1, Column2 from Table1 where UserId = 2 or UserId = 3 or UserId = 5 or UserId = 6 I'm very new to stored procedures, can anyone help me with the syntax for doing this. I'm being pressured to get this done very quickly. Thanks for any help!

View 5 Replies View Related

Nested Stored Procedure Question!

Jun 10, 2004

Hi,
i'm calling proc2, proc3 from proc1, as soon as proc1 initiates proc2 kicks in and after completion of proc2 only it will jump to proc3 and so on..right
Please clarify on this.
or it would be great if you refer to any manual which gives details aabout nested stored procedure execution criteria..
any help is greately appreciated..
thanks

View 3 Replies View Related

Problem For Nested Stored Procedure

Feb 21, 2008



Hello Guys,
I have a stored procedure. In the stored procedure, I update a value of table field. At the end of the stored procedure, I called another stored procedure. In the second stored procedure, I try to read the value of the field I just updated in the first stored procedure. However, The second stored procedure still get the old value of the field. But, sometimes, it is ok.

Any ideas?

Thanks in advance!

troy

View 1 Replies View Related

SQL 2012 :: Rollback Transaction In Nested Stored Procedure?

Nov 24, 2014

create proc proc1 (@param1 int)

as

begin try
declare @param2 int
begin transaction
exec proc2 @param2
commit transaction
end try
begin catch
if @@trancount > 0
rollback transaction
end catch

i haven't had an opportunity to do this before. I have nested stored proc and both inserts values into different tables. To maintain atomicity i want to be able to rollback everything if an error occurs in the inner or outer stored procedure.

View 3 Replies View Related

Need To Write A Stored Procedure

May 10, 2007

Hi,I need to write a stored procedure to check if the string = "web_version" exists in another string called FromCode.The stored procedure accepts 2 parameters like this:Create proc [dbo].[spGetPeerFromCode]( @FromCode VARCHAR(50)) (@WebVersionString VARCHAR(50))as   please assist. 

View 1 Replies View Related

How To Write Stored Procedure?

Jan 28, 2008

 
Hi all,
   I want to write a stored procedure for the following,
  The table have the following field,
  CategoryID, CategoryName,                    Parent_categoryID
  123             Kids Dresses                        0
  321             Kids Boys                            123
  322             Kids Baby                            123
  401             Kids Boys school Uniform     321
  501            Kids Boys Formals                321
  541            Kids Baby school Uniform      322
  542            Kids Baby Formals                322
  601            Household Textile                  0
  602           Bathrobe                               601
  603           Carpet                                  601
  604           Table Cloth                           601
 
 From the above example the categoryID acts as a parent_categoryID for some products,
 when i pass a categoryID the stored procedure should return all the categoryID which are subcategory to given categoryID,
 subcategory may contain some subcategory, so when i give a categoryID it should return all the subcategoryID.
 For example when i pass categoryID as 123 it should return the following subcategoryIDs
 321,322,401,501,541,542 because these are all subcategory of categoryID 123.
 How to write stored procedure for this?
 
Thanks!
 

View 2 Replies View Related

How Can I Write This Store Procedure

Jan 11, 2004

sql result:

startdate enddate price
2004-1-2 2004-1-4 677
2004-1-5 2004-1-8 900
2004-1-9 2004-1-12 2000


i want display in page this format:
2004-1-2 2004-1-3 2004-1-4 2004-1-5 ... 2004-1-12
677 677 677 900 2000

how can i write store procedure

View 1 Replies View Related

How To Write Stored Procedure

Mar 21, 2007

Hai Friends,
I heard that stored procedures can be written using two servers
how to write stored procedures by using two servers
CAN ANYONE GIVE INFORMATION ABT THIS

Malathi Rao

View 4 Replies View Related

How To Write Store Procedure

Dec 25, 2005

Hi,

I am new to using store procedures Can anyone please check and tell me whats wrong in it

 

create procedure Poll_Grid
@top int,
@ofset int,
@orderby varchar(50)
as

if (@orderby = "question")
 select top @ofset substring(question,1,50) question, startdate, username,categoryname from polls
 join users on polls.userid= users.userid
 join category on polls.categoryid= category.categoryid
 where pollid not in (select top @top pollid from polls order by Substring(@orderby,1,50))
 order by substring(@orderby,1,50)
else
 select top @ofset substring(question,1,50) question, startdate, username,categoryname from polls
 join users on polls.userid= users.userid
 join category on polls.categoryid= category.categoryid
 where pollid not in (select top @top pollid from polls order by @orderby)
 order by @orderby

 

I want to check if @orderby is passed as question it should fire the first query other wise last and also I want to dynamically insert the Ofset and top value for my paging require ment

 

Please help..

View 1 Replies View Related

Where Do You Write A Stored Procedure?

Mar 21, 2008

Hi, where do you write an SQL stored procedure?

View 1 Replies View Related

How Do You Write An UPDATE Store Procedure?

Oct 11, 2006

I have these 3 tables that are related to each other. I am trying to change the brand name of a product and the type of the product. How can I do this? 1 CREATE TABLE Products
2 (
3 ProductID int IDENTITY (1,1) PRIMARY KEY,
4 ProductSKU nvarchar(100) NOT NULL UNIQUE,
5 ProductName nvarchar(255),
6 ProductDescription nvarchar(MAX),
7 isInStock bit,
8 SalePrice decimal (18,2),
9 UnitPrice decimal (18,2),
10 isOnSale bit,
11 isSpecial bit,
12 isActive bit,
13 ProductRating int,
14 ProductImageBig varchar(255),
15 ProductImageMedium varchar(255),
16 ProductImageSmall varchar(255)
17 );
18
19 CREATE TABLE Brands
20 (
21 BrandID int IDENTITY (1,1) PRIMARY KEY,
22 BrandName nvarchar(255) NOT NULL UNIQUE
23 );
24
25 CREATE TABLE Types
26 (
27 TypeID int IDENTITY (1,1) PRIMARY KEY,
28 TypeName nvarchar(150) NOT NULL UNIQUE
29 );
30
31 // The store procedure I am having trouble with.
32
33 CREATE PROC SetProductsSKU_Brand_Type
34 @ProductID int,
35 @BrandName nvarchar(255),
36 @TypeName nvarchar(150),
37 @ProductSKU nvarchar(100),
38 @ProductName nvarchar(255),
39 @isInStock bit,
40 @SalePrice decimal (18,2),
41 @UnitPrice decimal (18,2),
42 @isOnSale bit,
43 @isSpecial bit,
44 @isActive bit
45 AS
46 UPDATE Products, Types, Brands
47 SET [BrandName] = @BrandName, [TypeName] = @TypeName, [ProductSKU] = @ProductSKU, [ProductName] = @ProductName, [isInStock] = @isInStock,
48 [UnitPrice] = @UnitPrice, [isSpecial] = @isSpecial, [isActive] = @isActive
49 FROM Products prod INNER JOIN ProductsBrands pb
50 ON prod.ProductID = pb.ProductID INNER JOIN Brands b
51 ON pb.BrandID = b.BrandID INNER JOIN ProductsTypes tp
52 ON prod.ProductID = tp.ProductID INNER JOIN Types t
53 ON tp.TypeID = t.TypeID
54 WHERE prod.ProductID = @ProductID
55 AND [ProductSKU] = @ProductSKU
56 AND [ProductName] = @ProductName
57 AND [isInStock] = @isInStock
58 AND [UnitPrice] = @UnitPrice
59 AND [isSpecial] = @isSpecial
60 AND [isActive] = @isActive
61 AND b.BrandName = @BrandName
62 AND t.TypeName = @TypeName
  

View 6 Replies View Related

How To Write Stored Procedure With Two Parameters

Aug 23, 2007

 How to write stored procedure with two parametershow to check those variables containing  values or  empty in SP
 if those two variables contains values they shld be included in Where criteiriea in folowing Query with AND condition, if only one contains value one shld be include not other one       
Select * from orders  plz write this SP for me thanks  

View 3 Replies View Related

How To Write A Stored Procedure In SQL Server2000?

Jan 28, 2008

 
Hi all,
 
  I want to write a stored procedure for the following,
  The table have the following field,
  CategoryID, CategoryName,                    Parent_categoryID
  123             Kids Dresses                        0
  321             Kids Boys                            123
  322             Kids Baby                            123
  401             Kids Boys school Uniform     321
  501            Kids Boys Formals                321
  541            Kids Baby school Uniform      322
  542            Kids Baby Formals                322
  601            Household Textile                  0
  602           Bathrobe                               601
  603           Carpet                                  601
  604           Table Cloth                           601
 
 From the above example the categoryID acts as a parent_categoryID for some products,
 when i pass a categoryID the stored procedure should return all the categoryID which are subcategory to given categoryID,
 subcategory may contain some subcategory, so when i give a categoryID it should return all the subcategoryID.
 For example when i pass categoryID as 123 it should return the following subcategoryIDs
 321,322,401,501,541,542 because these are all subcategory of categoryID 123.
 How to write stored procedure for this?
 
Thanks!

View 6 Replies View Related

Can Anyone Help Me To Write A Stored Procedure For The Following Scenario...

Feb 7, 2008

Hai friends, 
The project i'm working on is an asp.net project with SQL Server 2000 as the database tool.
I've a listbox (multiline selection) in my form, whose selected values will be concatenated and sent to the server as comma separated numbers (Fro ex: 34,67,23,60).Also, the column in the table at the back end contains comma separated numbers (For ex: 1,3,7,34,23).
What i need to do is -
1. Select the rows in the table where the latter example has atleast one value of the former example (In the above ex: 34 and 23).
2. Check the text value of these numbers in another table (master table) and populate the text value of these numbers in a comma separated format in a grid in the front end.
 I've programmed a procedure for this. but it takes more than 2 minutes to return the result. Also the table has over 20,000 rows and performance should be kept in mind.
Suggessions on using the front-end (asp.net 2.0) concepts would also be a good help.
 Anybody's helping thought would be greatly appreciated...
Thanks lot...

View 2 Replies View Related

How To Write A Procedure That Has To Execute On A Different SQL Server

Nov 1, 2005

Can I write a procedure that should connect to a different SQL server and execute a series of SELECT statement on that SQL SERVER.Reason being is I do not have permission to create procedure on that destination server while I have permission to execute a SELECT statement.  Please clarifyThanks,

View 3 Replies View Related

Read / Write Into .doc From SQL Stored Procedure

Jun 25, 2007

I need to create a flat file as word document, may i know how to write text from stored procedure if a file is already exist then the text will append, how to do it ?



Thank you.

View 1 Replies View Related

T-SQL (SS2K8) :: Nested Stored Procedure - Multiple Results Of Record Sets Coming

Oct 1, 2014

I am calling stored procedure called GetCommonItemCount within another stored procedure called CheckBoxAvailability, the first stored procedure should return a count to second stored procedure and based on that some logic will be executed.

I have 2 problems in that

1. The result is not coming from first stored so the variable called @Cnt is always 0 although it should be 18
2. At the end i need to see in the output the result from second stored procedure only while now i am seeing multiple results of record sets coming.

I have attached the scripts also, the line i described in step1 is

View 9 Replies View Related

Calling A Stored Procedure Inside Another Stored Procedure (or Nested Stored Procedures)

Nov 1, 2007

Hi all - I'm trying to optimized my stored procedures to be a bit easier to maintain, and am sure this is possible, not am very unclear on the syntax to doing this correctly.  For example, I have a simple stored procedure that takes a string as a parameter, and returns its resolved index that corresponds to a record in my database. ie
exec dbo.DeriveStatusID 'Created'
returns an int value as 1
(performed by "SELECT statusID FROM statusList WHERE statusName= 'Created') 
but I also have a second stored procedure that needs to make reference to this procedure first, in order to resolve an id - ie:
exec dbo.AddProduct_Insert 'widget1'
which currently performs:SET @statusID = (SELECT statusID FROM statusList WHERE statusName='Created')INSERT INTO Products (productname, statusID) VALUES (''widget1', @statusID)
I want to simply the insert to perform (in one sproc):
SET @statusID = EXEC deriveStatusID ('Created')INSERT INTO Products (productname, statusID) VALUES (''widget1', @statusID)
This works fine if I call this stored procedure in code first, then pass it to the second stored procedure, but NOT if it is reference in the second stored procedure directly (I end up with an empty value for @statusID in this example).
My actual "Insert" stored procedures are far more complicated, but I am working towards lightening the business logic in my application ( it shouldn't have to pre-vet the data prior to executing a valid insert). 
Hopefully this makes some sense - it doesn't seem right to me that this is impossible, and am fairly sure I'm just missing some simple syntax - can anyone assist?
 

View 1 Replies View Related

Hi I Want To Know How To Write Stored Procedure ..then I Have To Include (IF Condition ) With SP ..

Sep 20, 2007

hi i want to know how to write  stored procedure ..then i have to include (IF condition ) with SP ..
let me this post ..................anybody ??????????

View 5 Replies View Related

Could You Write A Special Stored Procedure For Me In SQL 2005?

Apr 6, 2006

Could you write a special stored procedure for me in SQL 2005?
When I execute the SQL "select TagName from Th_TagTable where IDTopic=@IDTopic" , it return several rows such as TagName= SportTagName= NewTagName= Health
I hope there is a stored procedure which can join all TagName into a single string and return,it means when I pass @IDTopic to the stored procedure, it return "Sport,New,Health"
How can write the stored procedure?

View 2 Replies View Related

Stored Procedure To Read And Write Between XML And SQLServer

Mar 28, 2004

Hi All,
I need some help from you experts.

I need to develop something that reads from xml files and writes in to sqlserver, also it should read from SQLServer and writes to xml.

I should be able to give this as a job to exectue daily ,etc.

Can we do this using stored procedures in SQLServer.
Pls paste some sample code, if any or direct me to any url with better info.

Thanks in advance

View 11 Replies View Related

Write To A Text File From A Stored Procedure

Oct 19, 2011

I have a sp which saves the necessary information regarding the status of action(whether success or failure, rows affected etc) to a log table say( StatusLog )After this, I was sending a database mail with information taken from the log table via sp_send_dbmail. Now I would like to write the status information to a 'txt' file instead of sending via mail.How can I write to a text file from a stored procedure in ms sql server 2005?

View 6 Replies View Related

Write An Xml File With A Stored Procedure RESOLVED

Sep 22, 2006

Can you, and if yes, how do you, write an xml file using a stored procedure. For example the sp below writes this new record to a sql table. How would I change it to write it to an xml file ?

CREATE Procedure [spOB_AddtblOB_Properties]

@strPropertyRef varchar (100),
@strRouteNo numeric,
@strAdd1 nvarchar(1000),
@strPostcode nvarchar(10)

as

Insert into tblOB_Properties (
PR_PropertyRef,
PR_RouteNo,
PR_Add1,
PR_Postcode)

values(
@strPropertyRef,
@strRouteNo,
@strAdd1,
@strPostcode)
GO

View 1 Replies View Related

Is It Possible To Write Clr Stored Procedure With Out Using Adomd Server.

Dec 5, 2006

hi,

I need to write a clr stored prodeure.i have to call that stored procedure from my prediction query.My Application is going to make use of that query to get the prediction output.

Is it possible to write clr stored procedure with out using adomd server.How?

For example:

In My Assembly i am having a function PredictPerformance(),Which is having my DMX Query.I need to execute that function from my analysis service by calling like this,

select aly. PredictPerformance() FROM [Model].

how to do this?

View 1 Replies View Related

Want To Write Store Procedure That Takes Parameter In SQL

Mar 5, 2008



Some one please tell me how do I write store procedure that receives/takes parameter values
I want to write store procedure which takes ID as a parameter

some one tell me how do I write store procedure that takes parameter
if possibel please show me example of it

iam new to this
thankyou


maxs

View 3 Replies View Related

Could You Write A Special Stored Procedure For Me In SQL 2005?

Aug 19, 2007



When I execute the SQL "select TagName from Th_TagTable where IDTopic=@IDTopic" , it return several rows such as
TagName= http://www.hothelpdesk.com
TagName= http://www.hellocw.com
TagName= http://www.supercoolbookmark.com


I hope there is a stored procedure which can join all TagName into a single string and return,
it means when I pass @IDTopic to the stored procedure, it return "http://www.hothelpdesk.com, http://www.hellocw.com, http://www.supercoolbookmark.com"

How can write the stored procedure?

View 1 Replies View Related







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