Home Forums SQL Server 2005 SQL Server Newbies Setting up SQL to only accept specific data in a specific field RE: Setting up SQL to only accept specific data in a specific field

  • I agree, not sure why you would ever want the same data in another column; maybe you should make it null or add a placeholder, and then do some calculation and populate later?

    You might do something like this?

    DROP TABLE #example

    GO

    CREATE TABLE #example(exampleId int identity(1,1) NOT NULL PRIMARY KEY,

    exampletext varchar(30),

    myCalculatedField AS SUBSTRING (ExampleText, CHARINDEX(':', exampleText )+1, len(exampleText)),

    myCalcd2 AS UPPER(LEFT(SUBSTRING (ExampleText, CHARINDEX(':', exampleText )+1, len(exampleText)),4))

    )

    GO

    INSERT INTO #example (exampletext)

    VALUES ('Product Description: Chair' )

    GO

    SELECT * FROM #example

    GO