Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


plz i need help!!!!


plz i need help!!!!

Author
Message
almany_13
almany_13
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 5
i want the entry for adding 2 value but i want show in the third cloumn all result with null value!!

need ur help:-)
J Livingston SQL
J Livingston SQL
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3454 Visits: 33044
almany_13 (1/27/2013)
i want the entry for adding 2 value but i want show in the third cloumn all result with null value!!

need ur help:-)


Hi...welcome to the site.

its a bit difficult to help you....I cant see what you can see....perhaps if you gave us the code for your query and some example data and expected results...we may be able to help

if you are unsure how to provide this...please post back...I assume you are using SQL 2005 ?

regards

________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day

Steven Willis
Steven Willis
SSC-Addicted
SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)

Group: General Forum Members
Points: 483 Visits: 1721


--create a table for some sample data

IF OBJECT_ID('tempdb..#TempTable') IS NOT NULL
DROP TABLE #TempTable

CREATE TABLE #TempTable (
[ID] INT NOT NULL,
[Col1] INT NULL,
[Col2] INT NULL,
PRIMARY KEY (ID))

--insert random numbers with a few nulls tossed in

INSERT INTO #TempTable
SELECT 1,ABS(CAST(NEWID() AS BINARY(6))%10)+1,ABS(CAST(NEWID() AS BINARY(6))%10)+1
UNION
SELECT 2,ABS(CAST(NEWID() AS BINARY(6))%10)+1,ABS(CAST(NEWID() AS BINARY(6))%10)+1
UNION
SELECT 3,NULL,ABS(CAST(NEWID() AS BINARY(6))%10)+1
UNION
SELECT 4,ABS(CAST(NEWID() AS BINARY(6))%10)+1,ABS(CAST(NEWID() AS BINARY(6))%10)+1
UNION
SELECT 5,ABS(CAST(NEWID() AS BINARY(6))%10)+1,NULL
UNION
SELECT 6,ABS(CAST(NEWID() AS BINARY(6))%10)+1,ABS(CAST(NEWID() AS BINARY(6))%10)+1

--raw table

SELECT * FROM #TempTable ORDER BY ID

--Col1+Col2 = Col3

SELECT
ID
,Col1
,Col2
,Col3 = ISNULL(Col1,0) + ISNULL(Col2,0)
FROM
#TempTable
ORDER BY
ID



almany_13
almany_13
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 5

C.K.Shaiju
C.K.Shaiju
SSC Veteran
SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)

Group: General Forum Members
Points: 214 Visits: 707
almany_13 (1/27/2013)









Did not understand the question properly. But can you please try the below script.



SELECT name, (CASE WHEN(salary) <= 0 THEN NULL ELSE salary END)
+ (CASE WHEN(bonuses) <= 0 THEN NULL ELSE bonuses END) ) as total
FROM YourTableName




_____________________________________________
One ounce of practice is more important than tonnes of dreams
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45247 Visits: 39929
No need for CASE here at all.
 SELECT Name,
Total = ISNULL(Salary,0) + ISNULL(Bonuses,0)
FROM dbo.YourTable
;


If you insist on ANSI/ISO code, you can replace ISNULL with COALESCE. I use ISNULL to make sure the datatype stays the same as the first operand and, over millions of rows, is a bit faster than COALESCE.

As a note for future posts, please read and heed the article at the first lik in my signature line below. Thanks.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
C.K.Shaiju
C.K.Shaiju
SSC Veteran
SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)

Group: General Forum Members
Points: 214 Visits: 707
Yes Jeff,

I had that thing in my mind. But in the first post he wants "result with a null value". I should have post both the scripts :-D

Thanks Jeff

almany_13 (1/27/2013)
i want the entry for adding 2 value but i want show in the third cloumn all result with null value!!

need ur help:-)


_____________________________________________
One ounce of practice is more important than tonnes of dreams
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45247 Visits: 39929
C.K.Shaiju (1/28/2013)
Yes Jeff,

I had that thing in my mind. But in the first post he wants "result with a null value". I should have post both the scripts :-D

Thanks Jeff

almany_13 (1/27/2013)
i want the entry for adding 2 value but i want show in the third cloumn all result with null value!!

need ur help:-)


Yet in the post where you offered your solution, you quoted the post where the op finally clarified and said "0 or noting[sic]". Not sure what wasn't clear about that.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
C.K.Shaiju
C.K.Shaiju
SSC Veteran
SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)

Group: General Forum Members
Points: 214 Visits: 707
Correct. In the first post he wants NULL and 2nd post 0 or Nothing (NULL). Thought he might be doing something with NULL. That's why I posted that script as a solution for both of his posts.

_____________________________________________
One ounce of practice is more important than tonnes of dreams
almany_13
almany_13
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 5
Thank societies... and I appreciate your help ;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search