MSSQL case statement
up vote
2
down vote
favorite
I want to create a view which only shows me values which have a % in it.
I tried following
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value text],2)
,[value_raw_text]
,[coverage_raw]
from .....
but I get the error
Incorrect syntax near ','.
any idea?
sql sql-server tsql
add a comment |
up vote
2
down vote
favorite
I want to create a view which only shows me values which have a % in it.
I tried following
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value text],2)
,[value_raw_text]
,[coverage_raw]
from .....
but I get the error
Incorrect syntax near ','.
any idea?
sql sql-server tsql
3
Classic. You forgot the "end" at the end of the case.
– George Menoutis
Nov 8 at 11:14
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I want to create a view which only shows me values which have a % in it.
I tried following
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value text],2)
,[value_raw_text]
,[coverage_raw]
from .....
but I get the error
Incorrect syntax near ','.
any idea?
sql sql-server tsql
I want to create a view which only shows me values which have a % in it.
I tried following
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value text],2)
,[value_raw_text]
,[coverage_raw]
from .....
but I get the error
Incorrect syntax near ','.
any idea?
sql sql-server tsql
sql sql-server tsql
edited Nov 8 at 12:53
Rahul Neekhra
514426
514426
asked Nov 8 at 11:13
cyberoner1
112
112
3
Classic. You forgot the "end" at the end of the case.
– George Menoutis
Nov 8 at 11:14
add a comment |
3
Classic. You forgot the "end" at the end of the case.
– George Menoutis
Nov 8 at 11:14
3
3
Classic. You forgot the "end" at the end of the case.
– George Menoutis
Nov 8 at 11:14
Classic. You forgot the "end" at the end of the case.
– George Menoutis
Nov 8 at 11:14
add a comment |
1 Answer
1
active
oldest
votes
up vote
5
down vote
There are tow things missing in your alter view statement:
One is the end
after the case
, and the other one is an alias to the column.
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value_text],2) end as value_text
,[value_raw_text]
,[coverage_raw]
from .....
You might also want to add an else
to the case
expression, otherwise it will simply return null
when the condition is not matched:
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value_text],2) else [value_text] end as value_text
,[value_raw_text]
,[coverage_raw]
from .....
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
There are tow things missing in your alter view statement:
One is the end
after the case
, and the other one is an alias to the column.
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value_text],2) end as value_text
,[value_raw_text]
,[coverage_raw]
from .....
You might also want to add an else
to the case
expression, otherwise it will simply return null
when the condition is not matched:
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value_text],2) else [value_text] end as value_text
,[value_raw_text]
,[coverage_raw]
from .....
add a comment |
up vote
5
down vote
There are tow things missing in your alter view statement:
One is the end
after the case
, and the other one is an alias to the column.
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value_text],2) end as value_text
,[value_raw_text]
,[coverage_raw]
from .....
You might also want to add an else
to the case
expression, otherwise it will simply return null
when the condition is not matched:
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value_text],2) else [value_text] end as value_text
,[value_raw_text]
,[coverage_raw]
from .....
add a comment |
up vote
5
down vote
up vote
5
down vote
There are tow things missing in your alter view statement:
One is the end
after the case
, and the other one is an alias to the column.
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value_text],2) end as value_text
,[value_raw_text]
,[coverage_raw]
from .....
You might also want to add an else
to the case
expression, otherwise it will simply return null
when the condition is not matched:
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value_text],2) else [value_text] end as value_text
,[value_raw_text]
,[coverage_raw]
from .....
There are tow things missing in your alter view statement:
One is the end
after the case
, and the other one is an alias to the column.
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value_text],2) end as value_text
,[value_raw_text]
,[coverage_raw]
from .....
You might also want to add an else
to the case
expression, otherwise it will simply return null
when the condition is not matched:
Alter VIEW [dbo].[history] as
select
[objid]
,[interval]
,[value_channel]
,[value_channelid]
,case when [value_text] like '[%]' then right([value_text],2) else [value_text] end as value_text
,[value_raw_text]
,[coverage_raw]
from .....
answered Nov 8 at 12:16
Zohar Peled
50.8k73171
50.8k73171
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206607%2fmssql-case-statement%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Classic. You forgot the "end" at the end of the case.
– George Menoutis
Nov 8 at 11:14