Results 1 to 4 of 4

Thread: Trigger problem

  1. #1
    Join Date
    May 2002
    Posts
    13

    Unanswered: Trigger problem

    Hello.
    I'm make a trigger in a database that contains user information.
    The trigger sends a mail for each new post.

    I'm kinda new to triggers and SP's .
    I want to get the results for a SELECT statement into a variable and I try to do it this way:

    SELECT @subject_String= select @lang from lang_strings where name = 'subject'

    I have 7 different languages and I want to gather all the strings in the chosen language (the one the user has chosen before)

    Now, the above clearly doesn't work but you probably get what I'm after.
    Does anyone know how I can accomplish this?

    /pelle

  2. #2
    Join Date
    Dec 2002
    Location
    Czech Republic
    Posts
    249

    Re: Trigger problem

    declare @subject_String int
    set @subject_String=(
    select @lang from lang_strings where name = 'subject'
    )

  3. #3
    Join Date
    May 2002
    Posts
    13
    Hello.

    It doesn't work.

    Let me explain a little bit more.
    I have a variable (@lang) that has the countrycode for the particular language.
    I take @lang from the inserted values, this works fine.

    What I then want is the particular strings in the choosen language from the table lang_strings.
    The lang_strings table has the following columns (NAME, EN,SV,FR,ES....an more) and for this example above, lets say that the user has choosen 'EN' as the language
    If I try the one you gave me above:

    set @subject_String=(select @lang from lang_strings where name = 'subject'
    )

    @lang contains 'EN' but If I later print out @subject_string the entire statement becomes 'EN'

    I've looked in BOL and it seems that I can only use variables in the where clause, not in the select clause...is this correct?
    Does anyone know another way?

    thanks
    /pelle

  4. #4
    Join Date
    Dec 2002
    Location
    Czech Republic
    Posts
    249
    /*
    I saw no brackets around your subquery and I did not
    notice "column" @lang inside so I adjusted just only outer query.
    */

    --THIS CAN BE WHAT YOU WANTED:

    --I.Normalize lang_strings table by moving "lang" columns to rows.
    select Value
    from lang_strings
    where lang=@lang and name = 'subject'

    --II. If you really have 7 languages only, use CASE
    select case @lang when 'EN' then EN when 'FR' then FR ... end
    from lang_strings
    where name = 'subject'

    --III.Use EXEC (or sp_executesql) to create dynamic query
    EXEC('select ['+@lang+'] from lang_strings where name = ''subject''')

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •