Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 14th, 2004, 01:45 AM
Authorized User
 
Join Date: Oct 2004
Location: , , Philippines.
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default creating stored procedure

hi guys,
how can i create one stored procedure that have one parameter that will find the field (received) that is null or not null

i have the sql that works but i want is one Sp only for these
thanx

  #2 (permalink)  
Old October 14th, 2004, 02:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You got to use dynamic sql then. construct the sql statement that takes the field parameter and then use EXEC function to execute that.
Code:
Create proc ProcName (@FIELDNAME varchar(100))
as
    Declare @strSql varchar(100)
    @strSql = "Select * from tablename where @FIELDNAME is NULL"
    Exec(@strSql)
    Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
  #3 (permalink)  
Old October 14th, 2004, 08:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

create procedure dbo.spGetNullOption

as

declare @IsNull int

select @IsNull = ISNULL(count(received), 0) from table1 where received is NOT NULL

'returns bit value
if (@IsNull > 0)
  return 1
else
  return 0

Brian


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating variables in a Stored procedure miamikk SQL Language 1 June 4th, 2007 03:02 AM
Creating stored procedure with trigger (HOWTO ..) AzlanAziz SQL Language 0 January 16th, 2007 04:34 AM
Creating Charts Using Stored Procedure srinivasparimi SQL Server 2005 1 August 7th, 2006 06:45 AM
Problem creating Stored Procedure vivekshah SQL Server 2000 4 May 28th, 2006 11:33 PM
Creating a stored procedure marthaj SQL Server ASP 8 June 10th, 2003 06:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.