Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

plz i need help!!!! Expand / Collapse
Author
Message
Posted Sunday, January 27, 2013 3:49 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, January 29, 2013 11:13 PM
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
Post #1412115
Posted Sunday, January 27, 2013 6:34 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Today @ 1:06 PM
Points: 1,456, Visits: 14,281
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 !
__________________________________________________________________
Post #1412120
Posted Sunday, January 27, 2013 8:01 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 8:48 PM
Points: 284, Visits: 1,249

--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


Post #1412166
Posted Sunday, January 27, 2013 10:12 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, January 29, 2013 11:13 PM
Points: 3, Visits: 5







Post #1412175
Posted Sunday, January 27, 2013 11:21 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, March 03, 2013 10:42 PM
Points: 179, Visits: 561
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


Post #1412192
Posted Sunday, January 27, 2013 11:55 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:36 PM
Points: 32,931, Visits: 26,820
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."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1412199
Posted Monday, January 28, 2013 8:34 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, March 03, 2013 10:42 PM
Points: 179, Visits: 561
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
Post #1412472
Posted Monday, January 28, 2013 4:45 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:36 PM
Points: 32,931, Visits: 26,820
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
"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."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1412700
Posted Monday, January 28, 2013 11:07 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, March 03, 2013 10:42 PM
Points: 179, Visits: 561
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.
Post #1412763
Posted Tuesday, January 29, 2013 1:13 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, January 29, 2013 11:13 PM
Points: 3, Visits: 5
Thank societies... and I appreciate your help
Post #1412799
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse