Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
I have Created a Portal in which when user enter some ID.then many columns associated for that ID shows up. Now i want that if user enter some specific IDs then values of some columns(NASSETS,Depreciation key)associated with That IDs should be fixed.

I want Nasset to be blank for some Asset Classes.I want depriciation key as 0000 for some Asset Classes.

Can I use "If Statement" in declarion of variable.

I have this stored procedure for that work.



JavaScript
SELECT FA.Asset_Class AS 'Asset Class',
           '1000' AS 'Company Code',
           '1' AS 'NASSETS',
           U.Asset_Desc AS 'Name',
           U.Asset_Desc+' ('+ U.Material_Code +')' AS 'Asset main no. text',
           UOM.Base_UOM AS 'Base Unit of Measure',
           'X' AS 'XHIST',
           'X' AS 'Include asset',
           '' AS 'Asset capitalization date',
           P.Plant_Name AS 'Business Area',
           C.CostCenter AS 'Cost Center',
           P.Plant_Name AS 'Plant',
           FA.IO_No AS 'Order',

           '01' AS 'Real depreciation area',
           'R999' AS 'Depreciation key',
           '' AS 'Planned useful life in years',
           '' AS 'Planned useful life in periods',
           '20' AS 'Real depreciation area',
           'R999' AS 'Depreciation key',
           '' AS 'Planned useful life in years',
           '' AS 'Planned useful life in periods',

           '4' AS 'AFASL_01',
           '4' AS 'AFASL_02'
Posted
Updated 22-Dec-15 18:03pm
v2

1 solution

It's not entirely clear what you mean but I'm fairly sure you want the CASE (Transact-SQL)[^] statement.

For example, using some test data generated by
SQL
-- Some test data
Create Table Table1
(
	id int identity(1,1),
	someTextData AS 'Data' + Cast(id as varchar),
	someDateData AS DATEADD(dd, id, CAST('2000-01-01' as Date))
)
go
insert into Table1 default values
go 100
You can adjust the results of the query thus
SQL
select 
	id, someTextData, someDateData, 

	CASE WHEN MONTH(someDateData) = 1 THEN 'January Sales' 
             ELSE someTextData 
        END as contrived

from Table1

On the other hand, if you mean that you have a variable declared and want to adjust it's value, you can still use the CASE statement
declare @AVariable INT = (select count(*) from Table1)
declare @AnotherVariable INT = CASE WHEN @AVariable > 50 then 1 else 0 end
select @AnotherVariable
If you are planning to do something a little more complex - e.g. multiple statements would depend on the condition then use the IF...ELSE (Transact-SQL)[^] statement
e.g.
IF @Avariable > 100 
BEGIN
	SET @AnotherVariable = 200
        --  ... do some other stuff
END
ELSE
BEGIN
	SET @AnotherVariable = 100
        --  ... do some other stuff
END 
select @AnotherVariable
 
Share this answer
 
Comments
Laviee 23-Dec-15 23:54pm    
I can not Return multiple values using case.
i want to return multiple values on conditions
CHill60 24-Dec-15 3:37am    
As I said, your question is not entirely clear and the code you posted was incomplete. You didn't mention returning multiple values from the SP.
I have given you an example of an IF statement - perhaps if you update your code based on that information with what you are trying to do I can help with any outstanding problem.
As to returning multiple values from the SP - how are you returning those values (there is more than one way to do that and it's not in your code snippet)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900