Solved

Query Help

Posted on 2011-02-22
5
208 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
HainKurt:,

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

Author Closing Comment

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

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now