Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    2

    Question Unanswered: SQL Stored Procedure issues

    Hi everyone,

    I'm fairly new to SQL, have been using it for sometime but am completely self taught so any help would be greatly appreciated. I could be approaching this from completely wrong angle.

    Here is the SQL SP I'm trying to write, what I want is to be able to create an additional column to the outcome that is the full name of the person by creating a string.

    ALTER PROCEDURE [dbo].[spGetTestimonialsHomePage]

    AS
    DECLARE @FullName nvarchar(100)
    SET @FullName = column[fsFirstName]+' '+column[fsLastName]
    SELECT fsFirstName, fsLastName, fsTetimonialSnippet,fdDate, @FullName
    FROM tblClients, tblTestimonials
    WHERE fbPublic = 1 and blkClientID = fkClientID


    I get the following error.

    Procedure spGetTestimonialsHomePage, Line 5
    Incorrect syntax near 'fsFirstName'.

    Thanks for your time in advance.

  2. #2
    Join Date
    Mar 2007
    Location
    Holmestrand, Norway
    Posts
    332
    Code:
    ALTER PROCEDURE [dbo].[spGetTestimonialsHomePage]
    AS
    SELECT fsFirstName, fsLastName, fsTetimonialSnippet,fdDate, fsFirstName+' '+fsLastName as FullName
    FROM tblClients, tblTestimonials
    WHERE fbPublic = 1 and blkClientID = fkClientID
    Apart from this, I don't apreciate prefixing very much, and in SQL Server sp is the prefix for special procedure (not stored procedure), and has a very specific meaning. If you still want to use prefixing, you should use pr for stored procs.

    Stored procs in the master database with a name starting with sp_ can be executed directly from any database, without prefixing it with master.., hence special procedure.
    Ole Kristian Velstadbråten Bangås - Virinco - MSSQL.no - Facebook - Twitter

  3. #3
    Join Date
    Jul 2011
    Posts
    2

    Thumbs up



    Thanks roac, this is exactly what I was after. Thanks for your time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •