473,661 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

generate & compare id from table in sql storeprocedure

25 New Member
hello sir,
goodevening....
iam working on vb6.0 and sql2005.

Expand|Select|Wrap|Line Numbers
  1.  "select max(centreid) from regionmaster where centreid like '" & intBranchPrefix & "%'", DBConnection, adOpenKeyset, adLockOptimistic
  2.          If rsMain.RecordCount > 0 Then
  3.             intID = Mid(rsMain(0), 3, 13)
  4.         End If
  5.          intCentreID = intBranchPrefix & (intID + 1)
  6.  
i have to convert the above code command in sql storeprocedure
where i have to generate centreid with branchprefix(ex :99 or 11) which is supplied by the application.i.e , intBranchPrefix. i have to take that branchprefix in storeprocedure and generate the centre id....that is
centerid=branch prefix & (id+!)
plz help me ......
prem........
Apr 30 '09 #1
11 2713
Delerna
1,134 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. create proc GenerateCentreID @intBranchPrefix int
  2. as
  3. declare @MaxCentreID int,@intID varchar(50)
  4. set @MaxCentreID=(select convert(int,max(substring(centreid,3,13)) 
  5.                   from regionmaster 
  6.                   where centreid like @intBranchPrefix%
  7.                   )
  8.  
  9. set @intID=@intBranchPrefix*10000000000000 + @MaxCentreID+1
  10. go
  11.  
I think thats right, you might need to fix some syntax. I haven't tested it
May 1 '09 #2
premprakashbhati
25 New Member
Mr.Delerna..Goo dMorning..,
i have got what u wrote but when i executed the proceure ..the error cameIncorrect syntax near ) of select statement
May 1 '09 #3
SnehaAgrawal
31 New Member
Hi the proc is correct just one closing bracket is missing
(int,max(substr ing(centreid,3, 13)))
I hope u got the ans.
May 1 '09 #4
Delerna
1,134 Recognized Expert Top Contributor
what is the data type of the field centreid in table regionmaster?
I will mock up a table so I can test the code.
I am guessing it is string but I don't want to guess
May 1 '09 #5
Delerna
1,134 Recognized Expert Top Contributor
if it is a character type then
Expand|Select|Wrap|Line Numbers
  1. create proc GenerateCentreID @intBranchPrefix varchar(20)
  2. as 
  3. declare @MaxCentreID bigint,@intID varchar(20) 
  4. set @MaxCentreID=(select convert(bigint,max(substring(centreid,3,13))) 
  5.                   from regionmaster 
  6.                   where centreid like @intBranchPrefix+'%'
  7.                   ) 
  8.  
  9. set @intID=@intBranchPrefix + convert(varchar(13),@MaxCentreID+1)
  10. select @intID
  11.  
  12. go 
  13.  
the error you mention was due to there not being enough closing brackets in the select criteria of the query.
Also the parameter was not the correct type.
Also I forgot the + '%' in the where
May 1 '09 #6
premprakashbhati
25 New Member
NOTE:datatype of centerid is decimal(13,2) in table...
here came the error when i execute the given proc

Argument data type decimal is invalid for argument 1 of substring function.
May 1 '09 #7
Delerna
1,134 Recognized Expert Top Contributor
Then try converting centreid to character in the query.
The like opperator works with strings!

Expand|Select|Wrap|Line Numbers
  1. create proc GenerateCentreID @intBranchPrefix varchar(20) 
  2. as  
  3. declare @MaxCentreID bigint,@intID varchar(20)  
  4. set @MaxCentreID=(select convert(bigint,max(substring(convert(varchar(20),centreid),3,13)))  
  5.                   from regionmaster  
  6.                   where convert(varchar(20),centreid) like @intBranchPrefix+'%' 
  7.                   )  
  8.  
  9. set @intID=@intBranchPrefix + convert(varchar(20),@MaxCentreID+1) 
  10. select @intID 
  11.  
  12. go  
  13.  
May 3 '09 #8
premprakashbhati
25 New Member
thanks Delerna...i got it..
May 4 '09 #9
premprakashbhati
25 New Member
hi delerna ...sorry for troubling u again...
when iam calling the store procedure from vb6 application in CmdSave_Click
it is giving Error:The Precision is invalid ...
iam not getting the exact thing/meaning...
so plz help me out...
here is the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SaveBranchProcedure()
  2.  
  3. Dim cmd  As New ADODB.Command
  4. Dim param1 As ADODB.Parameter
  5. Dim pm As Integer
  6. Dim i As Integer
  7.  
  8. Set cmd.ActiveConnection = DBConnection
  9.  
  10.      cmd.CommandType = adCmdStoredProc
  11. '     cmd.CommandText = "sp_savebranchmaster"
  12.        cmd.CommandText = "sp_branchonly"
  13.      cmd.Parameters.Append cmd.CreateParameter("BranchPrefix", adNumeric, adParamInput, 13, intBranchPrefix)
  14. '    cmd.Parameters.Append cmd.CreateParameter("centreid", adNumeric, adParamOutput, intID)
  15.     cmd.Parameters.Append cmd.CreateParameter("centretype", adVarChar, adParamInput, 3, "SR")
  16.     cmd.Parameters.Append cmd.CreateParameter("centrename", adVarChar, adParamInput, 60, Val(TxtName))
  17.     cmd.Parameters.Append cmd.CreateParameter("code", adVarChar, adParamInput, 6, Val(TxtCode))
  18.  
  19.     If CmbBusinessType.Text = "Booking" Then
  20.         cmd.Parameters.Append cmd.CreateParameter("BRANCH_BUSINESS_TYPE", adVarChar, adParamInput, 6, "BOOK")
  21.  
  22.     ElseIf CmbBusinessType.Text = "Delivery" Then
  23.         cmd.Parameters.Append cmd.CreateParameter("BRANCH_BUSINESS_TYPE", adVarChar, adParamInput, 6, "DELI")
  24.  
  25.     ElseIf CmbBusinessType.Text = "OTHER" Then '"Booking and Delivery"
  26.         cmd.Parameters.Append cmd.CreateParameter("BRANCH_BUSINESS_TYPE", adVarChar, adParamInput, 6, "BKDL")
  27.  
  28.     ElseIf CmbBusinessType.Text = "Transhipment" Then
  29.         cmd.Parameters.Append cmd.CreateParameter("BRANCH_BUSINESS_TYPE", adVarChar, adParamInput, 6, "TRAN")
  30.     End If
  31.  
  32.     cmd.Parameters.Append cmd.CreateParameter("levelno", adNumeric, adParamInput, 13, 0)
  33.     cmd.Parameters.Append cmd.CreateParameter("indexno", adNumeric, adParamInput, 13, 0)
  34.     cmd.Parameters.Append cmd.CreateParameter("groupno", adNumeric, adParamInput, 13, 0)
  35.  
  36.      cmd.Parameters.Append cmd.CreateParameter("group_node_flag", adVarChar, adParamInput, 1, "A")
  37.  
  38.      If Trim(TxtAddress) = "" Then
  39.         cmd.Parameters.Append cmd.CreateParameter("address", adVarChar, adParamInput, 4, Null)
  40.      Else
  41.         cmd.Parameters.Append cmd.CreateParameter("address", adVarChar, adParamInput, 50, Val(TxtAddress))
  42.     End If
  43.  
  44.      If Trim(txtAdd1) = "" Then
  45.         cmd.Parameters.Append cmd.CreateParameter("address1", adVarChar, adParamInput, 4, Null)
  46.      Else
  47.         cmd.Parameters.Append cmd.CreateParameter("address1", adVarChar, adParamInput, 50, Val(txtAdd1))
  48.     End If
  49.  
  50.      If Trim(txtAdd2) = "" Then
  51.         cmd.Parameters.Append cmd.CreateParameter("address2", adVarChar, adParamInput, 4, Null)
  52.      Else
  53.         cmd.Parameters.Append cmd.CreateParameter("address2", adVarChar, adParamInput, 50, Val(txtAdd2))
  54.     End If
  55.  
  56.        If Trim(TxtPhone) = "" Then
  57.         cmd.Parameters.Append cmd.CreateParameter("phone", adVarChar, adParamInput, 4, Null)
  58.      Else
  59.         cmd.Parameters.Append cmd.CreateParameter("phone", adVarChar, adParamInput, 20, Val(TxtPhone))
  60.     End If
  61.  
  62.     If Trim(TxtFax) = "" Then
  63.         cmd.Parameters.Append cmd.CreateParameter("fax", adVarChar, adParamInput, 4, Null)
  64.      Else
  65.         cmd.Parameters.Append cmd.CreateParameter("fax", adVarChar, adParamInput, 20, Val(TxtFax))
  66.     End If
  67.  
  68.     If Trim(TxtEmail) = "" Then
  69.       cmd.Parameters.Append cmd.CreateParameter("email", adVarChar, adParamInput, 4, Null)
  70.     Else
  71.       cmd.Parameters.Append cmd.CreateParameter("email", adVarChar, adParamInput, 30, Val(TxtEmail))
  72.    End If
  73.  
  74.     If Trim(TxtManager) = "" Then
  75.      cmd.Parameters.Append cmd.CreateParameter("manager", adVarChar, adParamInput, 4, Null)
  76.     Else
  77.      cmd.Parameters.Append cmd.CreateParameter("manager", adVarChar, adParamInput, 30, Val(TxtManager))
  78.     End If
  79.  
  80.     If Trim(TxtMgrPhone) = "" Then
  81.        cmd.Parameters.Append cmd.CreateParameter("MANAGER_PHONE", adVarChar, adParamInput, 4, Null)
  82.     Else
  83.       cmd.Parameters.Append cmd.CreateParameter("MANAGER_PHONE", adVarChar, adParamInput, 20, Val(TxtMgrPhone))
  84.     End If
  85.  
  86.     If Trim(TxtRemarks) = "" Then
  87.       cmd.Parameters.Append cmd.CreateParameter("REMARKS", adVarChar, adParamInput, 4, Null)
  88.     Else
  89.       cmd.Parameters.Append cmd.CreateParameter("REMARKS", adVarChar, adParamInput, 50, Val(TxtRemarks))
  90.     End If
  91.  
  92.     cmd.Parameters.Append cmd.CreateParameter("mainparent", adNumeric, adParamInput, 13, 0)  'frmTreeMaster.sngMainParentKey
  93.  
  94.  
  95.     If ChkAcct.Value = 1 Then
  96.       cmd.Parameters.Append cmd.CreateParameter("acct_y_n", adVarChar, adParamInput, 1, "Y")
  97.     ElseIf ChkAcct.Value = 0 Then
  98.       cmd.Parameters.Append cmd.CreateParameter("acct_y_n", adVarChar, adParamInput, 1, "N")
  99.     End If
  100.  
  101.     cmd.Parameters.Append cmd.CreateParameter("acct_branch", adVarChar, adParamInput, 20, vsgBranch.Text)
  102.  
  103.      cmd.Parameters.Append cmd.CreateParameter("CREATED_BY", adNumeric, adParamInput, 13, g_UserData.UserID)
  104.     cmd.Parameters.Append cmd.CreateParameter("CREATED_DATE", adDate, adParamInput, 13, Format(g_LoginData.ServerDate, "DD-MMM-YY"))
  105.     cmd.Parameters.Append cmd.CreateParameter("delete_flag", adVarChar, adParamInput, 1, "N")
  106.  
  107. cmd.Execute
  108.  
  109.  
  110. End Sub
  111.  
May 4 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2731
by: Mark A. Gibbs | last post by:
I have a string conversion function that looks something like this (apologies, but I cannot post the actual code): whar_t char_to_wchar(char); wstring to_wstring(const string& s) { wstring result(s.length(), '\0'); transform(s.begin(), s.end(), result.begin(), ptr_fun(char_to_wchar));
9
1480
by: vertigo | last post by:
Hello I have strange problem, i have map<myclass1*,myclass2*,Compare>. Code: std::map<myclass1*,myclass2*,Compare> m=mymap; std::map<myclass1*,myclass2*,Compare>::const_iterator ci; printf("Elements: %d\n",m.size()); for(ci=m.begin();ci!=m.end();ci++){ printf("text\n"); }
3
2474
by: Niyazi | last post by:
Hi, Me again. I want to create a SQL Server StoreProcedure and I want to access it with ADO.NET. I am using VB.NET. Creating StoreProcedure it was easy but my question is this. I have table with 4 Column and 6 rows. In the Column 3 for all rows I have to insert data. The data considt of the decimal value of Croiss Exchange and 6 my variable as:
1
2505
by: Megan | last post by:
quick summary: i'm having problems trying to group fields in a report in order to calculate percentages. to calculate percentages, i'm comparing the results from my grouped fields to the totals. first, let me say that this is a really long post. i wasn't sure how much information/ background to provide, so i thought more was better than less. i tried to delineate certain areas so that it would be easy to peruse my posting and find...
0
2252
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional assistance. I say additional because I've already had help which is greatly appreciated. I do try to take the time and understand the provided script in hopes on not having to trouble others on those. But here it goes...
3
3087
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn =server.createobject("ADODB.connection") objConn.open "DSN=Photo" Dim sqlSELsite,ObjRSSel sqlSELsite = "SELECT Name FROM tblbwday WHERE B'day ="& date() &" " '
1
2072
by: delif04031 | last post by:
How to implements storeprocedure in PostgreSQL?
5
5005
by: Yas | last post by:
Hello, I have the following table with 4 columns.... firstname, lastname1, lastname2, EMAIL Table has user names and email, I would like to generate a 5th column called DisplayName. The email Id is sometimes firstname.lastname1.lastname2@ and others just firstname.lastname1@ I would like to generate the display name exactly like the email eg
4
6308
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59 Notice: Undefined index: args in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92 Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.