Solved

Query Help

Posted on 2011-02-22
5
213 Views
Last Modified: 2012-05-11
Hello experts:

I have a table called dbo.hard_i  in this table I have these columns:

Column Name               Data Type               Maximum Length
-------------------                ---------------              -------------------------
bhrd_q1                          float                       NULL                
rchrd_q1                         float                       NULL
hd_11                             float                       NULL

I need to select bhrd_q1  and rchrd_q1  and if these columns IS NOT NULL than I need to move to
hd_11.

How would this be written in a query format?

Thank you for your help

0
Comment
Question by:algotube
  • 3
5 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 125 total points
ID: 34952935
I'm not sure what you need to move to 'hd_11', but the query would be something like this:

update dbo.hard_i set hd_11 = < the column to move >
where bhrd_1 is not null and rchrd_q1 is not null

Open in new window


0
 
LVL 51

Assisted Solution

by:HainKurt
HainKurt earned 125 total points
ID: 34953103
try these:

update dbo.hard_i
set hd_11 = isnull(bhrd_1, isnull(rchrd_q1,hd_11))

or

update dbo.hard_i
set hd_11 = isnull(bhrd_1, rchrd_q1)
where isnull(bhrd_1, rchrd_q1) is not null

or

update dbo.hard_i
set hd_11 = isnull(bhrd_1, rchrd_q1)
where bhrd_1 is not null or rchrd_q1 is not null
0
 

Author Comment

by:algotube
ID: 34953300
wdosanjos thank you for your reply very much appreciated.

I ran this query

USE Algoma_Lab_History
GO
SELECT bhrd_q1,rchrd_q1
FROM dbo.hard_i

bhrd_q1 rchrd_q1
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
399    NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
NULL  NULL
372    NULL
NULL  NULL
NULL  NULL
NULL  NULL

If the column does not contain a NULL like bhrd_q1  399 than I need to move it to hd_11. Same thing with rchrd_q1 if it does not contain a NULL than move it.


So I guess I could do this:

update dbo.hard_i set hd_11 = bhrd_1
where bhrd_1 is not null

and

update dbo.hard_i set hd_11 = rchrd_q1
where rchrd_q1 is not null

Thanks
0
 

Author Comment

by:algotube
ID: 34953318
HainKurt:,

Sorry just seen your reply............ I will take a look.........thanks
0
 

Author Closing Comment

by:algotube
ID: 34954812
Just wanted to say thank you to both of you today for helping very much appreciated. Have a great day.. :-)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question