Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Something is wrong in this SP ?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-01-05 : 08:12:35
Sagaar writes "Hi All...

When I run this SP it simply executes without err but doesn't insert data into database why?

Any pointers?

Regards
Sagar

CREATE PROCEDURE sp_CSTMST

(
@ST as NVarChar (10),
@NAME as NVarChar (97),
@SADD1 as NVarChar (30),
@SADD2 as NChar (30),
@SADD3 as NVarChar (30),
@SADD4 as NVarChar (30),
@SGNC as NChar (10),
@CNTY as NChar (4),
@OSC as NVarChar (10),
@LNG as NVarChar (4),
/*@TIME as datetime,*/
@SUP as NVarChar (1),
@PRE as NVarChar (1),
@NOD as NVarChar (10),
@FIN as NVarChar (4)
)

AS

IF Exists (SELECT CTYCOD FROM CTYMST)
BEGIN
IF NOT Exists (SELECT STNAME FROM CSTMST)
BEGIN
INSERT INTO CSTMST (STCUST, STNAME, STADD1, STADD2, STADD3, STADD4, STRGNC, STCNTY, STPOSC, DEFLNG/*, TIMESTAMP*/, SUPRPR, PREALR, ALRNOD, FINSTE)
VALUES (@ST, @NAME, @SADD1, @SADD2, @SADD3, @SADD4, @SGNC, @CNTY, @OSC, @LNG/*, CONVERT(BINARY(8), @TIME, 3)*/, @SUP, @PRE, @NOD, @FIN)
END

else
print 'sdfsd'

END
else
print 'asd'
GO"

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-05 : 08:30:53
IF Exists (SELECT CTYCOD FROM CTYMST)
i.e. if there is a row in CTYMST
and
IF NOT Exists (SELECT STNAME FROM CSTMST)
if CSTMST is empty
then do the insert
do you want
if exists (select * from CTYMST where CTYCOD = @CNTY)
if not exists (select * from CSTMST where STNAME = @NAME)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -