Solved

Query Help

Posted on 2011-02-22
5
214 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 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 53

Assisted Solution

by:Huseyin KAHRAMAN
Huseyin KAHRAMAN 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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