Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am working with a sql query where I have fields set dynamically but few of the fields values can be null,In case its null I want to fetch all the records with that column data.
like:
Select * from users where name=:name and class=:class;
Now suppose I have got value of only name variable and not the class,So now As class variable is not there It will give a error but I want to fetch users with all the classes in that case?
I tried this but it doesnt work:
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("name", request.params.name);
//run the query
How can I achieve this?
If parameter value is NULL then retrieve all value.
-- PostgreSQL
SELECT *
FROM users
WHERE (name = param_name OR param_name IS NULL)
AND (class = param_class OR param_class IS NULL);
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
There is EIID column with different strings value grouped and string column contains JPNaOn , PDSCLm , PDSCLs data values .
Please help me to filter the elID which contains only a particular value 'PDSCLm' and doesnot contains JPNaOn and PDSCLs column data for the particular EIID .
Is this what you are looking for?
SELECT EIID
FROM UserTable AS t
WHERE strings = 'PDSCLm'
AND NOT EXISTS (
SELECT 1
FROM UserTable AS t2
WHERE t.EIID = t2.EEID
AND t2.strings IN ('JPNaOn', 'PDSCLs')
);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to create a stored procedure which when called will return me multiple results
so a small variation in my sql code is:
#getnames = select * from mytable order by firstname;
#getActivename = select * from #getnames where Status = 19;
but that sems to be failing and i am not sure what i am doing wrong here
Perhaps you want :
select top (1) #getActivename = firstname
from mytable
where Status = 19
order by firstname;
According to your code you don't need to use two variables you can directly express it as by using single variable.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to add a star * to the end of the 'DisplayName' field of any record with a category of 2. Not sure how to do this but I think this is on the right track?
UPDATE `table_name`
SET `DisplayName` = replace(DisplayName, 'old_text', 'new_text')
WHERE Category = '2';
My problem is I need to just add a space and a character at the end, not do a find and replace.
The generic SQL would be:
UPDATE `table_name`
SET `DisplayName` = CONCAT(DisplayName, '*')
WHERE Category = '2';
CONCAT() can be spelled in different ways depending on the database -- such as + or ||.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
SQL is :
select name, value from config where parent_id in ( select id from config where
name = 'Yii');
I'm not sure about your condition but try to add sub query on condition field
$criteria = new CDbCriteria();
$criteria->select ='name, value';
$criteria->addCondition( select id from config where name = 'Yii');
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have an INSERT/UPDATE Procedure that will only seem to update when I change the existing "name".
I added a code field to the java, and want to update the code to the existing table without having to modify the "name" because it already exists. If I modify the "name" then the "code" will get updated to that row in the table.
Can someone help me understand whats going or what I need to modify?
thanks
PROCEDURE update_things
(things IN OUT things_bean, user_id IN NUMBER)
IS
t_things things_bean;
BEGIN
-- If there is already an id set ... this is an update
IF things.ID <> 0
THEN
SELECT things_bean (ID, NAME, code, work, foo)
INTO t_things
FROM things
WHERE things.ID = ID;
IF NOT things.equals (t_things)
THEN
things.foo:= t_things.foo;
things.foo.modified_date := SYSDATE;
things.foo.modified_by := user_id;
UPDATE things
SET NAME = things.NAME,
code = things.code,
foo= things.foo
WHERE ID = things.ID;
END IF;
END update_things;
looks to me like you should check this call:
things.equals(t_things)
to make sure your code value is part of the equality check.