Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Query Help

Posted on 2011-02-22
5
Medium Priority
?
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 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 59

Assisted Solution

by:HainKurt
HainKurt earned 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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