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.
| Author |
Topic |
|
krushnapanda
Starting Member
18 Posts |
Posted - 2007-11-14 : 00:11:55
|
| Hello Dear ,Please Solve my problem its Urgent.My Table is tblGenerateCodeFields are : SlNo,RefNo,Branch,Mode,TranDateSlNo is Identity = True columnMode is 2 types DD and TTRefNo is Generate Like this : Rf_SlNo/Branch/Mode/Month/YearExample : lets SP is sp_GenerateNothen execute the SPExec sp_GenerateNo 1,'','','MUMBAI,'DD','10-September-2007' I am passing only Branch,Mode,TranDateSlNo is Identity , RefNo is Generate automaticalyy like this 1/MUMBAI/DD/September/2007 next record 2/MUMBAI/DD/September/2007RefNo is generate as per Mode ,as per Month , as per BranchHow to generate this in SQL Server 2005 using SP i was done it The SP isAlter proc sp_GenerateNo(@Flag as int,@slno1 as int=null,@Branch as varchar(50),@RefNo as varchar(50)= null,@TranDate as datetime,@mode as varchar(50))asif @Flag = 1 -- InsertBegin Declare @Count44 As Numeric Select @Count44 = count(*) from tblGenerateCode Where @RefNo Like '%' + @Branch + '/' + @mode + '/' + DATENAME(month, @TranDate) + '%' Set @RefNo = cast(@Count44 + 1 as varchar) + '/' + @Branch + '/' + @mode + '/' + DATENAME(month, @TranDate) + '/' + convert(varchar(10),year(@TranDate)) Set @slno = cast(@Count44 + 2 as varchar) + '/' + @Branch + '/' + @mode + '/' + DATENAME(month, @TranDate) + '/' + convert(varchar(10),year(@TranDate)) Insert into tblGenerateCode values(@RefNo ,@Branch,@mode,@TranDate)Endelse if @Flag = 2 -- UpdateBegin End Please write me how to handel this at the time of updateWhen update the condition areif i update only the Date of the partcular transactionif i update only the month of the partcular transactionif i update only the Mode of the partcular transactionif i update the Month again and again of the partcular transactionThanks |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2007-11-14 : 00:29:58
|
You're data table structure does not follow very good practices. Please post your table structure, and what you are looking to do. Someone can probably point you in a better direction, unfortuantly the procedure you want to make work is likley just going to cause significant issues the larger your db grows.A basic update statement is thisUpdate aset a.MyColumn = @MyValuefrom Mytable awhere a.MyColumn = @MyCriteria but I don't think that's your issue. |
 |
|
|
krushnapanda
Starting Member
18 Posts |
Posted - 2007-11-14 : 02:39:44
|
| My Table is tblGenerateCodeFields are : SlNo,RefNo,Branch,Mode,TranDateSlNo is Identity = True columnMode is 2 types DD and TTRefNo is Generate Like this : Rf_SlNo/Branch/Mode/Month/Yearexample : when i pass Branch = 'Mumbai' , Mode ='DD' , TranDate = '10-Sep-2007'then the RefNo is look like this : 1/Mumbai/DD/September/2007is the Firset record, when i insert 2nd record for same branch ,same mode,same monththen the refno is look like this : 2/Mumbai/DD/September/2007This Rf_SlNo is generate base on Branch , Mode , Month Now plz write an SP for Insert and UpdateFor Insert its ok but at the time of updation i face this Problemssay i want to update this 2/Mumbai/DD/September/2007 recordsIf i update the Month Sep to Augustthen it should be count all RefNo from August then generate the Next For Augustsuppose in August total DD in Mumbai are 4 , then the updation records is like this5/Mumbai/DD/August/2007condition for Update records are : if i update only the Date of the partcular transaction the RefNo should not b changeif i update only the month of the partcular transaction the RefNo change acording To Monthif i update only the Mode of the partcular transaction the RefNo change if i update the Month again and again of the partcular transaction the RefNo change acordinglystill , if you not getting me then repl methanks Thanks |
 |
|
|
|
|
|
|
|