Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I almost got it!

Status
Not open for further replies.
Jul 25, 2000
33
0
0
US
Just need to be able to print out the value in next_value column but cant get it to go!

CREATE PROC spUpdFsrHeaderID


AS

--Declare parameters. Names = column headers

DECLARE @StartValue int
DECLARE @EndValue int
DECLARE @NextValue int
DECLARE @ValueWidth int

--declare new varriable new_next_value as an int as it will equal the next_value varriable plus
--1 plus the value_width varriable.

DECLARE @NewNextValue int

--set parameters to equal information already contained within the db

SELECT @StartValue = start_value, @EndValue = end_value,
@NextValue = next_value, @ValueWidth = value_width
FROM table_num_scheme
WHERE Name = 'FSR Header ID'

--Set NewNextValue to equal the NextValue + 1 + ValueWidth. This is the updated value
--in the next_value column.

SELECT @NewNextValue = @NextValue + 1 + @ValueWidth


--declare new varriable new_next_value as an int that will equal the next_value varriable plus
--1 plus the value_width varriable.


--make sure that new value is not greater than the end value (20000)
--and if it is reset the start_value column to "1"

IF @NewNextValue > @EndValue
UPDATE table_num_scheme
SET next_value = @StartValue
WHERE Name = 'FSE Header ID'


ELSE



PRINT @NextValue


 
Finally did it. Here is the final code. Dont need the help anymore but thanks anyways.

CREATE PROC spUpdFsrHeaderID
AS

--Declare parameters. Names = column headers

DECLARE @StartValue int
DECLARE @EndValue int
DECLARE @NextValue int
DECLARE @ValueWidth int
DECLARE @String varchar(20)
DECLARE @test int
--declare new variable new_next_value as an int as it will equal the next_value variable plus
--1 plus the value_width variable.

DECLARE @NewNextValue int

--set parameters to equal information already contained within the db

SELECT @StartValue = start_value, @EndValue = end_value,
@NextValue = next_value, @ValueWidth = value_width
FROM table_num_scheme
WHERE Name = 'FSR Header ID'

--Set NewNextValue to equal the NextValue + 1 + ValueWidth. This is the updated value
--in the next_value column.

SELECT @NewNextValue = @NextValue + 1 + @ValueWidth
SELECT @test = @NextValue

SELECT @string = 'newnextvalue: ' + convert(varchar(20), @newnextvalue)
print @string


--make sure that new value is not greater than the end value (20000)
--and if it is reset the start_value column to "1"

IF @NewNextValue > @EndValue
SELECT @newnextvalue = @StartValue

print 'begin update'
UPDATE table_num_scheme
SET next_value = @newNextValue
WHERE Name = 'FSR Header ID'
select @string = 'rowcount: ' + convert(varchar(20), @@rowcount)
print @string
--set up to show a return value that equals next_value


Select @string = 'Current value: ' + Convert(varchar(20), @test)
PRINT @string
GO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top