How do i replace a sql tables field value with another value

50 pts.
Tags:
SQL
SQL scripts
SQL tables
I have the following script that works in Access but not in sql. I trying to replace the the value in the field "RSAMSTORE" with another value I give it (i.e. 999994, etc.) when the data is displayed. In otherwords when the select distinct is ran instead of seeing the value in the table "RSAMSTORE" I will see the substituted value "999994" Unfortunately I'm getting syntax error. thank you. SQL Script sample: SELECT DISTINCTROW IIf([sub2group]='RSAMSTORE','999994',IIf([sub2group]='RNEWSTORE','999995', IIf([sub2group]='PSAMSTORE','999996',IIf([sub2group]='PNEWSTORE','999997','999999')))) from oas_el2groupstr1

Answer Wiki

Thanks. We'll let you know when a new response is added.

You can’t use the IIF command in SQL Server. The SQL Server command to use would be the CASE statement.

<pre>SELECT DISTINCT CASE WHEN RSAMSTORE = 999994 THEN
YourValue
WHEN RSAMSTORE = 9999995 THEN
AnotherValue
ELSE
DefaultValue
END
FROM oas_el2groupstr1 </pre>

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Denny Cherry
    Check out my SQL Server blog "SQL Server with Mr Denny" for more SQL Server information.
    66,000 pointsBadges:
    report
  • Bhonimbi
    FLame: Thanks very much, you saved me a lot.
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following