problem in sql server

  • Hi friends i have small doubt in sql server plese tell me how to solve this issue.

    table data contains like

    id

    1234567890

    based on that data i want display output like

    id

    15

    i tried like this

    select stuff(id,2,3,'') from table

    but its not display exactely output.

    plese tell me query how to solve this issuse in sql server.

  • Well, this would do it:

    SELECT 15 AS id

    but I suspect that's not what you're looking for, so please explain exactly how you get the second value from the first.

    John

  • Your post is very unclear. How is the 15 (you want to display) related to 1234567890 (the value in the column)?

    If you execute: "SELECT 15 as 'ID' " you have your desired output, but I don't think that would be the solution :w00t:.

    Edit: I see John has posted the same solution allready 😀

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • Something like this at all?

    Details are pretty vague!

    DECLARE @id INT = 1234567890

    SELECT LEFT(stuff(@id,2,3,''),2)

    Andy

    ==========================================================================================================================
    A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe

  • John Mitchell-245523 (6/26/2013)


    Well, this would do it:

    SELECT 15 AS id

    Really liked the killer idea. :laugh:

    The problem should be mentioned clearly. Then only any help can be expected.

  • These solutions will all give the desired output

    DECLARE @MyVal BIGINT = 1234567890

    SELECT 15

    SELECT (@MyVal / 100000000) + 3

    SELECT (@MyVal * 0) + 15

    SELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(CAST(@MyVal AS VARCHAR(20)), '2', ''), '3', ''), '4', ''), '6', ''), '7', ''), '8', ''), '9', ''), '0', '')

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply