1

%w in ruby allows one to separate array using whitespace instead of using quotes:

Ruby

%w(one two three)

Is there an equivalent function in SQL Server?

SQL Server

select case when 'one' in ('one', 'two','three') then 1 else 0 end
Community
  • 1
  • 1
WiredIn
  • 4,157
  • 4
  • 27
  • 23

2 Answers2

0

Since this is SQL everything is either a table, a column or a row. You can sort of do it like this:

DECLARE @Numbers TABLE (Number varchar(10))

INSERT INTO @Numbers(Number) VALUES ('one'),('two'),('three')

SELECT CASE WHEN 'one' IN (SELECT Number FROM @Numbers) THEN 1 ELSE 0 END

Super-verbose, I know, but you have to consider this is a 70s-era language.

Code Different
  • 90,614
  • 16
  • 144
  • 163
0

No.

The %w method is Ruby Syntatic Sugar for initializing an array of strings separated by spaces.

As mentioned by Zoff, SQL being a much older language, does not have anything like this.

WiredIn
  • 4,157
  • 4
  • 27
  • 23