Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 missing quote

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2014-10-20 : 07:51:51
Hello,

declare @value varchar(100)
set @value = ('uk', 'us', 'en')

Let's say I have a variable as above which gets populated from the UI...
I would like to check if the variable has the correct single quotes around the text.
So the user can miss one or more of the single quotes and so I would like to check for that.
I would like the sql to show that there are missing single quotes
Due to business rules, there is no UI code available.
So do you know how this can be done in sql please?
Thanks

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-20 : 09:04:40
First off, that is invalid syntax. In SQL Server you cannot set a variable to a tuple. This would work


declare @value varchar(100)
set @value = '''uk'''
if left(@value,1) <> '''' or right(@value,1) <> ''''
print 'not enclosed in sinqle quotations'
Go to Top of Page
   

- Advertisement -