• you are missing the FROM clause. you can't select a column name without it's table.

    SpeedSkaterFan (11/30/2015)


    Hi all,

    I am trying to split (incorrect) cellcontents into smaller pieces.

    If I use:

    SELECT cdsDescription

    , CHARINDEX(' ',cdsDescription) AS [1stPos]

    , CHARINDEX(' ', cdsDescription, CHARINDEX(' ',cdsDescription) + 1) AS [2ndPos]

    [highlight="#ffff11"]FROM tbCompdistances[/highlight]

    the code works fine.

    If I try to simplify the code (which will grow) for easier reading, and try to use a variable SQL Server states that "cdsDescription" is an invalid column name.

    The code I use:

    DECLARE @FirstBlankPosition INTEGER

    SET @FirstBlankPosition = CHARINDEX(' ', [cdsDescription], 1)

    [highlight="#ffff11"]FROM tbCompdistances[/highlight]

    Is it possible to do what I want, or is the code invalid.

    Thanks in advance

    Hein

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!