Home Forums SQL Server 2005 T-SQL (SS2K5) how to verify blank spaces using substr function in SQLSERVER 2008 RE: how to verify blank spaces using substr function in SQLSERVER 2008

  • I would agree with Phil that this is not the best way to split a string. I would go one step further and suggest that you have a function called Usp_split_words but it only sort of splits them. You added a bunch of other stuff to it to. If you want to learn how to split strings using t-sql follow the link in my signature about splitting strings.

    From the code you posted it looks like all you are trying to do is allow the data to be inserted if there are no spaces. There is no need to split this and there is no need to loop. The following code will do that with little effort:

    declare @word varchar(125) = 'The Quick Brown Fox Jumps over a lazy Dog'

    if LEN(@word) = LEN(replace(@word, ' ', ''))

    Print 'Word inserted will be ' + @word

    --Insert into Word_entry values (@word)

    else

    Print 'sorry you entered blank spaces can not insert record'

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/