Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #38420

Re: Is there a SQL hashmap?

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Is there a SQL hashmap?
Date 2018-06-26 22:36 +0200
Message-ID <fpfmegF9ol2U1@mid.individual.net> (permalink)
References <031dadbc-3c27-4021-9b1d-8cb860c5e9f6@googlegroups.com>

Show all headers | View raw


On 26.06.2018 18:03, Eric Douglas wrote:
> I'm using JDBC with java.sql.PreparedStatement on SQL Server 2012.
> 
> I'm trying to write a translate that says "select <map value> (where
> table1.field = <map key>) from table1"
> 
> Getting a bit tired of writing it as "select iif(table1.field =
> 'first key','first value',iif(table1.field = 'second key','second
> value','default')) from table1"

Why do you use SQL Server's non standard IFF which requires uuhgly 
nesting when there is CASE?

SELECT CASE field
   WHEN 'first key' THEN 'first value'
   WHEN 'second key' THEN 'second value'
   ELSE 'default'
   END AS mapped
FROM table1

I guess a separate table with index and joining is more efficient if the 
number of mappings gets large.

> Just a better syntax to do such a thing within the SQL, or a way to
> pass the values as a parameter?  Ideally I would just create a table
> and write the values there and join that table, but I don't want to
> alter that database which was created by our third party
> application.

Another option might be to create another database on the same server 
with the new table and join cross databases if SQL Server can do that.

> I was hoping to avoid the other option, modifying the code that gets
> the results of the query to translate that result field, since this
> section of the code is generic - used to send the results of multiple
> queries to a spreadsheet.

Oh, lots of constraints.

Cheers

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Is there a SQL hashmap? Eric Douglas <e.d.programmer@gmail.com> - 2018-06-26 09:03 -0700
  Re: Is there a SQL hashmap? Arne Vajhøj <arne@vajhoej.dk> - 2018-06-26 12:23 -0400
  Re: Is there a SQL hashmap? Robert Klemme <shortcutter@googlemail.com> - 2018-06-26 22:36 +0200
    Re: Is there a SQL hashmap? Eric Douglas <e.d.programmer@gmail.com> - 2018-06-26 14:02 -0700
      Re: Is there a SQL hashmap? Arne Vajhøj <arne@vajhoej.dk> - 2018-06-27 20:22 -0400
        Re: Is there a SQL hashmap? firstsql@gmail.com - 2018-06-27 20:53 -0700
        Re: Is there a SQL hashmap? Eric Douglas <e.d.programmer@gmail.com> - 2018-06-28 05:03 -0700
          Re: Is there a SQL hashmap? Eric Douglas <e.d.programmer@gmail.com> - 2018-06-28 06:49 -0700
            Re: Is there a SQL hashmap? Eric Douglas <e.d.programmer@gmail.com> - 2018-06-28 07:38 -0700
              Re: Is there a SQL hashmap? Andreas Leitgeb <avl@logic.at> - 2018-06-28 15:52 +0000
                Re: Is there a SQL hashmap? Martin Gregorie <martin@mydomain.invalid> - 2018-06-28 19:47 +0000
                Re: Is there a SQL hashmap? Arne Vajhøj <arne@vajhoej.dk> - 2018-06-28 18:34 -0400
                Re: Is there a SQL hashmap? Martin Gregorie <martin@mydomain.invalid> - 2018-06-28 23:20 +0000
                Re: Is there a SQL hashmap? Arne Vajhøj <arne@vajhoej.dk> - 2018-06-28 20:07 -0400
                Re: Is there a SQL hashmap? Eric Douglas <e.d.programmer@gmail.com> - 2018-06-29 05:11 -0700
                Re: Is there a SQL hashmap? Martin Gregorie <martin@mydomain.invalid> - 2018-06-29 12:30 +0000
                Re: Is there a SQL hashmap? Eric Douglas <e.d.programmer@gmail.com> - 2018-06-29 06:11 -0700
                Re: Is there a SQL hashmap? Martin Gregorie <martin@mydomain.invalid> - 2018-06-29 13:43 +0000
                Re: Is there a SQL hashmap? Robert Klemme <shortcutter@googlemail.com> - 2018-06-29 23:20 +0200
                Re: Is there a SQL hashmap? Martin Gregorie <martin@mydomain.invalid> - 2018-06-29 22:34 +0000
                Re: Is there a SQL hashmap? Arne Vajhøj <arne@vajhoej.dk> - 2018-06-30 16:36 -0400
                Re: Is there a SQL hashmap? Martin Gregorie <martin@mydomain.invalid> - 2018-06-30 23:00 +0000
              Re: Is there a SQL hashmap? Robert Klemme <shortcutter@googlemail.com> - 2018-06-29 23:34 +0200
            Re: Is there a SQL hashmap? Arne Vajhøj <arne@vajhoej.dk> - 2018-06-30 17:51 -0400
              Re: Is there a SQL hashmap? Eric Douglas <e.d.programmer@gmail.com> - 2018-07-03 07:13 -0700

csiph-web