How to use sql in parametre [closed] - sql

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
Declare #record_status varchar(50)
İf #record_status=‘X’
#record_status=‘A’
Else if #record_status Is null
#record_status=‘’’A’’,’’P’’’
Select*from .....where RECORD_STATUS in(#record_status)
Else if not searching in the sql somebody help to me

IF you mean what I think you mean, this could do it...
SELECT
*
FROM
yourTable
WHERE
(#record_status = 'X' AND table.record_status = 'A')
OR
(#record_status IS NULL AND table.record_status IN ('A', 'P'))
But your post is very vague ;)

Related

Write Oracle SQL queries [closed]

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 10 months ago.
Improve this question
how to rank each country based on number of people in SQL.
Try
SELECT * FROM (
SELECT country, count(people) as count FROM your_table GROUP BY country
) ORDER BY count DESC

SQL Join...Issue with joins [closed]

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 need help regarding SQL joins, i am trying join two tables as shown in below images
I guess you can try the below query to get the desired result -
SELECT CASE WHEN CT.partner2 IS NULL
THEN C.partner_id
ELSE CT.partner1
END Partner1,
CT.partner2,
C.Type,
C.Company_name,
C.First_name,
CT.city,
CT.Phone,
CT.Email
FROM CUSTOMER C
LEFT JOIN CONTACTS CT ON C.partner_id = CT.partner2

Get CR_NO values for the same table in sql [closed]

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 2 years ago.
Improve this question
Some can help me on this query? I need this
You can use the exists as follows:
Select cr_no, so, id
From your_table t
Where exists (select 1 from your_table tt
Where t.cr_no <> tt.cr_no
And t.so = tt.so
And t.id = tt.id)

How can I get the Unit Number to be displayed in place of the "ID" [closed]

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 7 years ago.
Improve this question
How can I write a SQL query that will replace the "ComputerID" and "PartID" with the "UnitNumber". The ComputerID's and PartID's are in the same column under InventoryID. The InventoryID's are unique but the UnitNumber (sticker label/name) doesn't have this requirement.
Here are the tables and how they relate.
Let's call your tables Object and Inventory
If you use a couple of joins then this should work:
select o.ObjectID as ObjectID, a.UnitNumber as Computer, b.UnitNumber as Part,
o.InputID from Object o
join Inventory a on a.InventoryID=o.CombputerID
join Inventory b on b.InventoryID=o.PartID

SQL Server and Transact-SQL [closed]

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 7 years ago.
Improve this question
IF EXISTS((SELECT user_type FROM users WHERE user_id=#user_id)=2)
BEGIN
UPDATE users SET Status=2 WHERE User_id=#user_id
END
You can try this
IF EXISTS(SELECT user_type FROM users WHERE user_id=#user_id and user_type=2)
BEGIN
UPDATE users SET Status=2 WHERE User_id=#user_id
END
What you have done that is not feasible syntax in Sql
I think You are try to achieve this..
IF ((SELECT top 1 user_type FROM users WHERE user_id=#user_id)=2)
BEGIN
UPDATE users SET Status=2 WHERE User_id=#user_id
END