January 27, 2013 at 3:49 am
i want the entry for adding 2 value but i want show in the third cloumn all result with null value!!
need ur help:-)
January 27, 2013 at 6:34 am
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
January 27, 2013 at 8:01 pm
--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
January 27, 2013 at 10:12 pm
January 27, 2013 at 11:21 pm
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
January 27, 2013 at 11:55 pm
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
Change is inevitable... Change for the better is not.
January 28, 2013 at 8:34 am
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 😀
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
January 28, 2013 at 4:45 pm
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 😀
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
Change is inevitable... Change for the better is not.
January 28, 2013 at 11:07 pm
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
January 29, 2013 at 1:13 am
Thank societies... and I appreciate your help 😉
January 29, 2013 at 10:16 pm
C.K.Shaiju (1/28/2013)
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.
Ah! Got it.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 30, 2013 at 7:07 pm
This looks like a school assignment. I think rather then giving him code we should send him some good tutorials.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply