SQL - Multiple Replace [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
what i try to do is a multiple replace of an variable string.
but the problem that nothing happend.
i can´t figured out what is wrong in the code:
can someone give me hand with this pls?
here is the sql code:
SET #HTML = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(#EMAILBODY2SEND,
'#%LoginUser%#',#Name),
'#%Number%#',#Number),
'#%classification%#',#classification),
'#%Phone%#',#Phone,
'#%Date#',#Date)

Hope following query can make your life easier by not nesting too many parentheses.
SET #HTML = #EMAILBODY2SEND;
SELECT #HTML = REPLACE(#Html, P, R)
FROM (VALUES ('#%LoginUser%#',#Name),
('#%Number%#',#Number),
('#%classification%#',#classification),
('#%Phone%#',#Phone),
('#%Date#',#Date)
) AS T(P, R)

Related

It seems like my min/max functions for my SQL code are reversed [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 days ago.
Improve this question
I'm using Microsoft SQL Server and I"m having issues writing a command for MIN and MAX functions.
It seems simple. The data type of the column is date time and the requested information is to find oldest/newest employee.
Below is the query I wrote:
select max(date_hired)
from staff;
select min(date_hired)
from staff;
But it seems like they are working in reverse. Min is giving me oldest and max is giving me youngest.

Wrongly closed SQL parentheses [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm fairly new at writing SQL commands so I don't exactly know where I'm going wrong here. I closed all the parentheses, but I still get the following error message:
Syntax error: Expected ")" but got keyword AND at [18:5]
Code:
goals as (
select sum(cast(goal as int64)) as goal
from seed.seed_ads_goals
goal_total
and extract(month from [daterange_start]) = month
)
Any hints?
WHERE Clause is missing :
select sum(cast(goal as int64)) as goal
from seed.seed_ads_goals as goal_total
where extract(month from [daterange_start]) = month

How to get exact result from charindex? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
select *
from table_name
where charindex(dest_mail,'abc#mail.com') >0
In the above query dest_mail is a column, but there is another entry in the table, which is 'bc#mail.com'. When I try to execute the above query, I'm getting two results
1.abc#mail.com
2.bc#mail.com
How to get exact 'abc#mail.com'?
Have you considered =?
where dest_mail = 'abc#mail.com'
Also, charindex() is not very colloquial SQL for this purpose; = is a built-in standard operator (charindex() is not standard). And a bonus to = is that it allows the optimizer to take advantage of indexes and partitions.

ORA-00918 Column ambiguously defined [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
SELECT INDIVIDUAL.INV_FNAME,
INDIVIDUAL.INV_LNAME,
INDIVIDUAL.INV_IC_NUM,
CUSTOMER.MEMBER_LEVEL,
CUSTOMER.MEMBER_POINT_BALANCE,
CUSTOMER.MEMBER_DISCOUNT_RATE,
PROGRAM_USER.USER_CONTACT_NUM,
PROGRAM_USER.USER_ADDRESS,
PROGRAM_USER.USER_CITY,
PROGRAM_USER.USER_STATE,
PROGRAM_USER.USER_ZIP_CODE,
PROGRAM_USER.USER_COUNTRY,
PROGRAM_USER.USER_EMAIL
FROM PROGRAM_USER,CUSTOMER,INDIVIDUAL
WHERE USER_ID = ‘san’;
In your query only USER_ID column in the where condition is not specified with a table name. I guess USER_ID is there in multiple table. Try the where condition with proper table name
SELECT INDIVIDUAL.INV_FNAME,
INDIVIDUAL.INV_LNAME,
INDIVIDUAL.INV_IC_NUM,
CUSTOMER.MEMBER_LEVEL,
CUSTOMER.MEMBER_POINT_BALANCE,
CUSTOMER.MEMBER_DISCOUNT_RATE,
PROGRAM_USER.USER_CONTACT_NUM,
PROGRAM_USER.USER_ADDRESS,
PROGRAM_USER.USER_CITY,
PROGRAM_USER.USER_STATE,
PROGRAM_USER.USER_ZIP_CODE,
PROGRAM_USER.USER_COUNTRY,
PROGRAM_USER.USER_EMAIL
FROM PROGRAM_USER,CUSTOMER,INDIVIDUAL
WHERE PROGRAM_USER.USER_ID = ‘san’;
Also like #HoneyBadger comment you need to specify the join between the tables

Incorrect syntax near '.\'. in sql [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
When I ran the query I am getting incorrect syntax error. can any one help me to fix it?
SELECT
si.SoftwareImage as ImagePLName,
SUBSTRING(si.SoftwareImage, 0, CHARINDEX(\'.\',si.SoftwareImage)),
sib.SoftwareImageBuild as BuildID
FROM
v000001.SoftwareProductBuilds spb
JOIN
v000001.SoftwareProductBuildSoftwareImageBuilds spbisib ON spbisib.SoftwareProductBuildId = spb.SoftwareProductBuildId
JOIN
v000001.SoftwareImageBuilds sib ON sib.SoftwareImageBuildId = spbisib.SoftwareImageBuildId
JOIN
v000001.SoftwareImages si ON si.SoftwareImageId = sib.SoftwareImageId
WHERE
spb.SoftwareProductBuild = '123456'
It should be:
CHARINDEX('.\',si.SoftwareImage)
Documentation to CHARINDEX for SQL Server
Documentation to CHARINDEX for Sybase.