Numbering system in Sql Server

hi
i am using sql server 2008 & vs 2008 C#
i have table
[tbl_CashCounter](
[Id] [int] IDENTITY(1,1) NOT NULL,
[BillNo] [nvarchar](50) NULL,
[BillDate] [datetime] NULL
i want BillNo  A0001,A0002,..........A9999.
if it reached A9999 it should new series like  B0001,B0002,..........B9999.
then C,D,.........Z
i am looking sql function or store procedure which will return max  Series No.
i want use like this
txtBillNo.text =  getMaxNo();
Thanks Best Regard Naweez

As per your scenario, below the code is working fine as well as good performance. Code was tested in SQL SERVER 2008 R2.
CREATE FUNCTION getMaxNo()
RETURNS VARCHAR(5)
AS
BEGIN
DECLARE @Max_no varchar(5), @numeric int
SELECT @Max_no= ISNULL(MAX(BillNo),'A0001') FROM [tbl_CashCounter]
SET @numeric=CAST(RIGHT(@Max_no,4) AS INT)+1
SELECT @Max_no=(CASE WHEN RIGHT(@Max_no,4)=9999 THEN char(ASCII(left(@Max_no,1))+1)+'0001'
ELSE left(@Max_no,1) END)
+''+
ISNULL(CASE WHEN len(@numeric)=1 THEN '000'+CAST(CAST(RIGHT(@Max_no,4) AS INT)+1 AS VARCHAR(4))
WHEN len(@numeric)=2 THEN '00'+CAST(CAST(RIGHT(@Max_no,4) AS INT)+1 AS VARCHAR(4))
WHEN len(@numeric)=3 THEN '0'+CAST(CAST(RIGHT(@Max_no,4) AS INT)+1 AS VARCHAR(4))
WHEN len(@numeric)=4 THEN ''+CAST(CAST(RIGHT(@Max_no,4) AS INT)+1 AS VARCHAR(4))
END,'')
RETURN @Max_no
END
GO
Regards,
RAMBHARATH
thanks its working fine i just modified
alter FUNCTION getMaxNo()
RETURNS VARCHAR(5)
AS
BEGIN
DECLARE @Max_no varchar(5), @numeric int
SELECT @Max_no= ISNULL(MAX(BillNo),'A0001') FROM [tbl_CashCounter]
SET @numeric=CAST(RIGHT(@Max_no,4) AS INT)+1
SELECT @Max_no=
(CASE WHEN RIGHT(@Max_no,4)=9999 THEN char(ASCII(left(@Max_no,1))+1)+'0001'
ELSE left(@Max_no,1)
END)
+''+ ISNULL( replicate('0', 4 - len(@numeric)) + CAST(CAST(RIGHT(@Max_no,4) AS INT)+1 AS VARCHAR(4)),'')
RETURN @Max_no
END
GO
Thanks Best Regard Naweez

Similar Messages

  • How to export SSIS package to File system in SQL Server 2012

    I am accessing SSIS package by connecting to a database engine. I wanted to export the SSIS to file system. How to get it done in sql server 2012? I tried Util utility , i got package not present. Let me know what other options are available to export to
    file system?
    Mano

    Hi Mano,
    After exporting the project stored in a SSISDB catalog to an .ispac file, we can modify the extension .ispac to .zip, then, we can extract the zip file to get the .dtsx package files. Besides, please note that if there are project level connection managers
    or parameters, their definition cannot be exported to individual packages.
    Regards,
    Mike Yin
    TechNet Community Support

  • Change Tracking System in SQL Server 2012

    Hi,
    I have enabled change tracking to one of the database with retention period 1 day and auto clean is true. As per this setting changed data of one day old should get cleaned up automatically. But i am able to see 4 days
    old data also using CHANGETABLE function. Let me know is there any other setting or is this an issue in SQL server 2012 which quires some patch?
    SQL Server configuration: SQL Server 2012, Enterprise Edition, 64 bit.
    Thanks in advance for the support.
    Aruna Veluru

    please paste out:
    select * from sys.change_tracking_databases

  • Source System creation in BI 7.0 for SQL Server using DB Connect

    Hi
    My requirement  is to extract data from SQL Server 2005 to BI 7.0 using DB Connect.
    I need to create a SOURCE SYSTEM for that purpose,As i am new to BW i don't know how to start to create a  SOURCE SYSTEM.
    What are the parameters i require either from Basis team to install or for DB team User ID in SQL (What type of user).
    Questions:
    1)  create a db user with authorization to read this views.......as i created views on tables...do i need authorisation to read table or views
    "On BW Server side (If BW server isn't based on SQL Server):
    (1) Install SQL Server client and test connection to SQL Server DB.
    (2) Install DBSL of SQL server (download lib_dbsl_<num>.sar file from service market and sapcar to BW kernel)"
    How can i know on which server our BW System is Based and HOW Install SQL Server client and test connection to SQL Server DB and
    Install DBSL of SQL server (download lib_dbsl_<num>.sar file from service market and sapcar to BW kernel
    and
    how to create Source System to SQL Server on BW
    Please update me in details i this is my first Source System Creation in BW
    Thanks in advance

    go through the link this may be helpful                  http://msdn.microsoft.com/en-us/library/dd299430.aspx

  • SQL Server 2000 Enterprise Edition Compatability with Latest Operating Systems

    Hi Team,
    My client is using SQL Server 2000 Enterprise edition for the database in the Production.
    Now,We are planning to load that data from SQL 2000 to SQL 2012 and test the functionality.
    Can you please tell me on which operations systems the SQL Server 2000 is compatible to Install ?
    like Windows Server 2012/ 2012 R2/ Windows 7/ 8 etc.
    Thanks
    Srikrishna

    Installing SQL Server 2000 on Windows 2008 or later is not supported, but your question is about compatibility rather than support.  SQL Server 2000 may work with the database engine but not with some other features and you'll probably need
    to click through warnings installation. Proceed at your own risk if you want to go down that path.
    I suggest you install on Windows 2003 for your migration testing to avoid obstacles.  Not that support ends for Windows Server 2003 in a few months.
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • Homogeneous system copy for SQL server 2005

    Hi All,
    I am currently investigating for the method to perform system copy for a PI system with SQL server 2005 database. Using the System Copy for SAP Systems Based on NW 7.0 SR2 ABAP+Java as guide, I can see reference to Note 151603. However, I am unable to get a copy of that note. Searching for the note from the official SAP Notes Search area indicated that it is currenytly only avaiable internally.
    Would anyone know where I will be able to get a copy of that note?
    Thanks,
    Wi

    > I am currently investigating for the method to perform system copy for a PI system with SQL server 2005 database. Using the System Copy for SAP Systems Based on NW 7.0 SR2 ABAP+Java as guide, I can see reference to Note 151603. However, I am unable to get a copy of that note. Searching for the note from the official SAP Notes Search area indicated that it is currenytly only avaiable internally.
    PI is version 7.1 (not 7.0) - so you need to use a different system copy guide.
    Markus

  • SQL Server system setup

    I want to connect 5 computers for a database system using sql server. I will make one of the computers as database server and the other 4 will be client machines. Which operating system should  I use for clients and server?. Do I need to install Windows
    Server 2008 on the database server or can Win 7 Pro is enough for all machines both server and clients.

    it depends on the version and edition of sql server that you want to install.
    check this link -
    http://msdn.microsoft.com/en-us/library/ms143506.aspx#pmosr
    It contains the different operating systems supported for different editions of SQL 2014.
    Regards, Ashwin Menon My Blog - http:\\sqllearnings.com

  • System copy EP on SQL Server

    Hi,
    I am trying to perfom system copy from an EP Netweaver 7.0 SR3 production system to a development system.
    My production system is a Java only, High Availability system with SQL server.
    I have finished the export process using the sapinst tool and I have created a folder EXPORT which I copied to the new server (target system). In the target system (not high availability) I have prepared the OS (windows) and I have installed SQL server. I started sapinst selecting system copy - target system - central system - based on AS Java - central system from sapinst.
    After few steps the procedure prompts for "Migration Export" media. I enter the path of the folder that I have copied erlier but I get the following error:
    You entered: X:\IMPORT\JAVA Found the label SAP:JMIG:700:::* but need the label SAP:MIGJDMP:700:::*
    Onother question that I have is:
    Do I have to install the SAP EP first in target systme using normal procedure and then to use the system copy procedure in target system?
    Can anyone help me?
    Thanks in advanced.

    Hi,
    As per SAP Note 151603 :Note 151603 - Copying an SQL Server database,
    For Java or ABAP + Java systems that are based on NetWeaver technology lower than Version 7.10,
    you must first export parts of the Java source system. For this, you must use the delivered SAP installation master DVD
    of your installed SAP release. The export of the Java part into a file is then created using the option 'system copy'.
    Have you used the same IM, which is corresponding to your Installed SAP EP release ?
    Regards,
    Bhavik G. Shroff

  • RSA1 DB Connection from SAP BW to external SQL Server databas.

    Hello,
    I am trying to connect our SAP BW system with SQL Server Source System through DB Connect in transaction RSA1.
    Our BW system is running on Windows and MaxDB platform, therefore have I already added the latest dbmssslib.dll library to the kernel for SQL Server.
    But the connection does not work anyhow, I recieve the error "Database error -1 at CON > [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does > exist or access denied." and I am quite sure that my input parameters are correct.
    Therefore I wonder if someone has run into a similar problem and what the problem could be?
    Best Regards,
    Niklas Sandstedt

    Hi,
    I am sorry that my case was assigned to wrong forum.
    That should now have been corrected, however my problem still remains unsolved in one of our systems.
    I found note 178949, which fixed the problem in one system. But even though the system setup seems to be identical, the two systems appears different.
    The following has been done for both systems:
    1. Upgraded kernel to 701 version 111 and added dbmssslib.dll and dbmssslib.pdb files
    2. Created Logical system in BD54.
    3. Tried to create DB connection in transaction DBACOCKPIT.
    In the third step, the setup fails and I receive the following error message when I test the connection:
    Database error -1 at CON > [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not > exist or access denied.
    Database error -1
    All profile parameters AL11-directories also seems to be correct in both systems, so both should find the dbmssslib.dll file.
    One issue that I see is in DBACOCKPIT, the checkbox for "SAP Systems with basis release" is unchangeble and marked. This however, I think was changed in the other system automatically when the connection was established successfully.
    Has anyone run into the same problem?
    Best Regards,
    Niklas Sandstedt

  • DBConnect with SQL Server

    Hi,
    we have a dbconnect source system with sql server.
    The installation is correct and we have the list of tables and views.
    We can get a list of table/view content too.
    But, when we make an infopackage request there is no idoc generated and the status color of the request get yellow.
    Tips:
    - We have in SQL the user with permissions to do selects and create views.
    - The list of tables/views in source system not extract this user owner. Only extracts the sa owner.
    - We connect with our user, not with sa.
    Any one have an idea
    Tanks
    Xavo

    Hi,
    This is some sort of privileges problem . The user which is used in  the Source system definition ,Should have Atleast select statement privileges on the table and view. If you are using view you can change the owner of this view to user , which is used in the Source system definition .
    With rgds,
    Anil Kumar Sharma .P

  • Executing SSIS packages through SQL Server Jobs.

    Hi,
    I have an SSIS package which generates xml and text files and ftps it to an ftp site. When i run the package from BIDS it works successfully but when i run it from a job it fails. My SSIS package connects to DB server A and though i'm creating a job on DB
    server A but my folder structure and the package resides in server B from where i'm connecting to DB server A through Management Studio. I'm using File system in SQL server Agent Job to call the package. When i execute the job i get following error:
    Executed as user: I\A. ...er Execute Package Utility  Version 9.00.3042.00 for 64-bit  Copyright (C) Microsoft Corp 1984-2005. All rights reserved.    Started:  5:08:05 PM  Error: 2011-06-21 17:08:05.11         
    Description: Unable to load the package as XML because of package does not have a valid XML format. A specific XML parser error will be posted.  End Error  Error: 2011-06-21 17:08:05.11         Description:
    Failed to open package file "E:\P\H\R\Tools\R\R\R.dtsx" due to error 0x80070003 "The system cannot find the path specified.".  This happens when loading a package and the file cannot be opened or loaded correctly into the XML document. This can be the
    result of either providing an incorrect file name was specified when calling LoadPackage or the XML file was specified and has .  The step failed.
    Could you please tell me where am i going wrong?
    Thanks,
    Deepti
    Deepti

    Hi Christa Kurschat,
    I'm running the job under proxy account. And that account has sysadmin permissions.
    I used following script to create proxy account and run my package under that account:
    I. Create job executor account
    Highlight Security->New Login, say to make login as devlogin, type your password, default database can be your target database.
    Server roles: check �sysadmin�
    User mapping: your target database
    Msdb database: you make sure to include
    SQLAgentUserRole, SQLAgentReaderRole,  SQLAgentOperatorRole
    Then click OK
    II. Create SQL proxy account and associate proxy account with job executor account
    Here is the code and run it the query window.
    Use master
    CREATE CREDENTIAL [MyCredential] WITH IDENTITY = 'yourdomain\myWindowAccount', secret = 'WindowLoginPassword'
    Use msdb
    Sp_add_proxy @proxy_name='MyProxy', @credential_name='MyCredential'
    Sp_grant_login_to_proxy @login_name=' devlogin', @proxy_name='MyProxy'
    Sp_grant_proxy_to_subsystem @proxy_name='MyProxy', @subsystem_name='SSIS'
    III. Create SSIS package
    In MS SQL Server Business Intelligence Development Studio, you use job executor account devlogin to create the SSIS package (DTS) and make sure you can execute this package
    in SQL Server Business Intelligence Development Studio. Compile/build this package.
    IV. Create the job, schedule the job and run the job
    In SQL Server Management Studio, highlight SQL Server Agent -> Start. Highlight Job ->New Job�, name it , myJob.
    Under Steps, New Step, name it, Step1,
    Type: SQL Server Integration Service Package
    Run as: myProxy
    Package source: File System
    Browse to select your package file xxx.dtsx
    Click Ok
    Schedule your job and enable it
    I followed these steps.
    Thanks,
    Deepti
    Deepti

  • Does it need effort to upgrade SSRS from SQL Server 2005 to 2014?

    Hi,
    i have a customer who wants to upgrade the their system. for SQL Server part, the current version is 2005, they want to upgrade to 2014. is it possible that don't change any code for SSRS? if have to change, what's the estimated effort? the total RDL files
    are more than 200. 

    Hi dingsheng,
    In this scenario, you don't need to change code for Reporting Services. Those reports can be still available. Please run SQL Server Upgrade Advisor on the report server computer to determine any issues that might prevent you from successfully upgrading.
    For more information, please see:
    Upgrade and Migrate Reporting Services
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • Linked Server unable to Connect in SQL Server 2012 after Restarting SQL Server Service it works fine. Why?

    I have created a Linked Server to Access Database of 64 MB in Size located in Remote System to SQL Server 2012.In Start for Some time it works fine and after it is giving the Error 
    OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "LANDLINE_TEST" returned message "Cannot open a database created with a previous version of your application.".
    Msg 7303, Level 16, State 1, Procedure Insert_Records_Into_Actual_Calls_History, Line 29
    Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "LANDLINE_TEST".
    Previously I thought it as Permission Issue. By trying some fixes proposed in forums it not fixed. But, after restarting the SQL Server Services without changes to the linked Server it works perfectly. How could i fix it. I don't want restart the SQL Server
    Service it leads to Some other process failures.
    RehaanKhan. M

    After all the Errors, When I am restarting the SQL Server its working correctly.
    Whats the problem it is clearing itself after restarting of SQL Server. Why ?. I can't find anything regarding this in SQL Server .
    The following are the Errors i got connecting to SQl Server.
    OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "LANDLINE_TEST" returned message "Cannot open a database created with a previous version of your application.".
    Msg 7303, Level 16, State 1, Procedure Insert_Records_Into_Actual_Calls_History, Line 29
    Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "LANDLINE_TEST".
    Error-2:
    Executed as user: RMS\Administrator. Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "LANDLINE_TEST". [SQLSTATE 42000] (Error 7303)  OLE DB provider
    "Microsoft.ACE.OLEDB.12.0" for linked server "LANDLINE_TEST" returned message "Cannot open a database created with a previous version of your application.". [SQLSTATE 01000] (Error 7412).  The step failed.
    After unchecking the Allow In Process in OLEDB.ACE Provider Properties.
    Msg 7399, Level 16, State 1, Procedure Insert_Records_Into_Actual_Calls_History, Line 29
    The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "LANDLINE_TEST" reported an error. Access denied.
    Msg 7301, Level 16, State 2, Procedure Insert_Records_Into_Actual_Calls_History, Line 29
    Cannot obtain the required interface ("IID_IDBCreateCommand") from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "LANDLINE_TEST".
    for to fix above error i have followed the instructions in the following link,
    http://blogs.msdn.com/b/dataaccesstechnologies/archive/2010/08/19/permissions-needed-to-set-up-linked-server-with-out-of-process-provider.aspx
    This also failed to work. I Restarted SQL Server and make the Linked Server Properties Default to my Configuration and it works fine.
    Can you suggest me a solution for this issue. Every time i don't want to restart SQL Server Services as it effects other jobs and Processes.
    Thank you.
    RehaanKhan. M

  • SQL Server Management Studio or DB13?

    Hi all, I would like to know if there are some best practices for maintaining a SAP System on SQL Server 2008 R2 Enterprise Edition 64bit.
    I am interested in administrative tasks like backup db, backup t-log, checkdb, reindex, alerting, notifications and so on.
    We do all these tasks with Management Studio for other databases and this is fine.
    What about SAP databases?
    Should we use DB13 or can we continue to use Management Studio?
    Thank you very much.
    Best regards.

    Hi,
    What about SAP databases?
    Should we use DB13 or can we continue to use Management Studio?
    You can use DB13. Most of administrative tasks are incorporated in it.
    You can refer SQLServerFAQ.zip file attached with [SAP Note 555223 - FAQ: Microsoft SQL Server|https://service.sap.com/sap/support/notes/555223] to get Info.
    You can also refer this [Best Practice Document|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/4ab89e84-0d01-0010-cda2-82ddc3548c65] to get more detailed information.
    Regards,
    Bhavik G. Shroff
    Edited by: Bhavik G. Shroff on Jul 13, 2011 4:54 PM

  • Why SCCM 20012 Install fails with remote 64 bit SQL Server but proceeds for remote 32 bit SQL Server

    I have the following setup:
    AD User accounts
    - SQLAdmin (used to run SQL Services i.e. Database Engine)
    - SCCMADmin (used to install SCCM 2012)
    SPN registered for user account SQLAdmin
    setspn -S MSSQLSvc/SQL.Domain_Name:1432 Domain_Naem\SQLAdmin
    setspn -S MSSQLSvc/SQL:1432 Domain_Name\SQLAdmin
    setspn -S MSSQLSvc/SQL.Domain_Name:1433 Domain_Naem\SQLAdmin
    setspn -S MSSQLSvc/SQL:1433 Domain_Name\SQLAdmin
    and checked with setspn -L TESTING\SQLAdmin
    1 SERVER called SQL
    32bit Server with SQL Server 2008 + SP3 + Cumulative Update 6
    2 SQL instances - Default (MSSQLSERVER) and
    SCCM2012
    MSSQLSERVER instance uses TCP port 1433
    SCCM2012 Instance users TCP port 1432 (no dynamic ports)
    User accounts that have been given public and sysadmin SQL server roles
    on both instances are: SQLAdmin, SCCMAdmin, Domain Administrator, Local Administrator and computer account SCCM
    Client Protocols TCP enabled (and Named Pipes) (checked via SQL Server Configuration Manager)
    Local Administrators Group on this server has members - SQLAdmin, SCCMAdmin, Domain Administrator, Local Administrator and computer account SCCM
    Firewall turned on with access allowed on Ports 1432, 1433, 4022,445, and WMI - WMI-in, DCOM-in and ASync-iN builtin rules allowed\enabled.
    1 SERVER called SQL3
    64bit Server with SQL Server 2008 + SP3 + Cumulative Update 6
    2 SQL instances - Default (MSSQLSERVER) and
    SCCM2012
    MSSQLSERVER instance uses TCP port 1433
    SCCM2012 Instance users TCP port 1432 (no dymanic ports)
    User accounts that have been given public and sysafmin SQL server roles on both instances are:
    SQLAdmin, SCCMAdmin, Domain Administrator, Local Administrator and computer account SCCM
    Client Protocols TCP enabled (and Named Pipes) (checked via SQL Server Configuration Manager)
    Local Administrators Group on this server has members - SQLAdmin, SCCMAdmin, Domain Administrator, Local Administrator and computer account SCCM
    Firewall turned off
    1 SERVER called SCCM
    64bit Server that is to be the Primary Site Server\MP for SCCM 2012
    ODBC link to SQL\SCCM2012,1432
    ODBC link to SQL3\SCCM2012,1432
    ODBC uses SQL Native Client 10.0 (64 bit)
    Both ODBC connections when TESTed pass and suggest connectivity to SQL Servers
    Install process doe SCCM2012
    Tried to install SCCM 2012 RC2 when logged in to SCCM Server as AD user account
    SCCMAdmin,  and when utilising the SCCM2012 SQL instance on
    32 bit server of SQL install proceeds barring warning about 8GB rec, for SQL Server. Then fails on PKI certificate issue. Installation (chose HTTP for MP). I beleive the PKI failure as install starts is
    due to the fact that SCCM 2012 needs its database server to b 64 bit ?
    Thus i then tried to install SCCM 2012 RC2 when logged in to SCCM Server as AD user account SCCMAdmin,  and
    when using the SCCM2012 SQL instance on
    64 bit server of SQL install proceeds but fails at checking stage and says:
    SQL Server sysadmin rights FAILED SQL3.Domain_Name
    Either the user account running Configuration Manager Setup does not have sysadmin SQL Server role permissions on the SQL Server instance selected for site database installation, or the SQL Server instance could not be contacted to verify permissions. Setup
    cannot continue.
    and
    Site System to SQL Server communication  WARNING SCCM.Domain_Name
    A communication error has been detected between the specified site system and the site database computer. This error can occur when the site database server is offline or if a valid SPN has not been registered in Active Directory Domain Services for the SQL
    Server instance hosting the site database. Setup cannot continue.
    Why does the install of SCCM 2012 with 32 bit SQL proceed further than the install with 64 bit SQL, with the latter process failing as above error meesages show and yet both servers are set identically (apart from temporary turning off Firewall on the 64 
    bit server) and during the install the Databse Server specified is accepted ?

    Thanks for the reply.
    I can connect via ODBC to the the 32 bit SQL Server and the 64 bit SQL Server from the SCCM Server
    The SQL Server Unit called SQL3 unit is a 64 bit SQL.
    The SQL Server Unit called SQL is only 32 bit, but at least gets past the final checking stage and the error messages about sysadmin rights and Site System to SQL Server communication problem, and then fails with PKI certificate error message. 
    When trying to install SCCM specifying the 64 bit SQL Server as the Database Server it gives the 2 error messages at the final checking stage of the installation as listed.
    So as I said what is confusing is the fact that if the SCCM install uses the remote 32 bit SQL Server it passes the final checking (although fails with PKI certificate message) but the 64 bit SQL Server set up exactly the same apart from the Firewall being
    left off for the time being, fails at the final check stage with the 2 listed errors.
    If I use a local 64 bit SQL Server the installation is fine.
    Still would like to find out what cause the 2 issues for the remote 64 bit SQL Server, when ODBC seems fine, sysadmin rights have been given for the installer account and the SCCM computer account and SPNs have been set for the user account running the SQL
    Services.

Maybe you are looking for