Having 2 parameters equate to one parameter

Posted on 2011-10-31
Last Modified: 2012-05-12
I would like to take two parameters in SQL with SQL Server and concatenate them to be passed to one varchar parameter.  How would I take the two parameters, which must take user input and then pass it all to a larger stringed parameter which essentially gets used into the query?  Thanks!
Question by:VBBRett
    LVL 31

    Expert Comment

    by:James Murrell

    Author Comment

    OK, I am looking for something much simpler then that.  Let's say I have the following:

    @cn as varhcar(6)
    @mn as varchar(5)

    cmn as varchar(12) = @cn + '-' + @mn

    How would I declare cmn so that it is not a required parameter for a user to fill in but it is still used in my query?
    LVL 6

    Assisted Solution

    declare @cmn varchar(12)
    set @cmn=@cn + '-' + @mn

    LVL 15

    Accepted Solution

    create procedure MyProc
    (@cn as varhcar,
    @mn as varchar)
    declare @cmn varchar(12)
    set @cmn=@cn + '-' + @mn
    ....bla bla bla

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now