Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sgandhi
Posting Yak Master
115 Posts |
Posted - 2009-02-19 : 13:41:06
|
| Hi,I need to write some code to do thisIf column1 = 'Y' then column2 is not null, else it can be null.I need to enforce that if column1 is 'Y' there HAS to be a value in column2Im having trouble writing this. Can someone help. |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-19 : 13:45:28
|
| [code]Case When col1 ='Y' then Coalesce(col2,value) Else Null End[/code] |
 |
|
|
SQLforGirls
Starting Member
48 Posts |
Posted - 2009-02-19 : 13:53:27
|
| http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=120062Why are you reposting? It seems that visakh16 gave you a good suggestion yesterday regarding SSIS.The reason your post went back and forth so many times yesterday is that the original question is confusing. Reposting the original confusing question is not going to get you a more clear answer. People are thinking that you conditionally want to populate column2 with a non-null value, when what I think you're really asking is to conditionally disallow population of column2 with a null value.Did you try the SSIS solution from yesterday? If so and you are still having trouble, or if you need more clarification on the solution, you should probably post back to the original thread so people will have a clear chance of helping you further.Good luck. |
 |
|
|
sgandhi
Posting Yak Master
115 Posts |
Posted - 2009-02-19 : 14:03:09
|
| I dont want to confuse it with yesterdays discussion.I dont want to do it in SSIS, i want to put it inside a stored proc with other things i am doing.I think my wording today is more clearer. |
 |
|
|
SQLforGirls
Starting Member
48 Posts |
Posted - 2009-02-19 : 14:14:36
|
| ------------------------------------------OK, let me explain the whole scenario.I have a whole bunch of different file formats (XML, XLS, CSV etc) which i am using SSIS to load into a temporary table.From this table i am writing a stored proc to insert the data into another table, applying business rules to it and doing validation.The TMP table data is being loaded to is called dbo.INITIAL_INTERNATIONAL_CATALOGThe Table i am finally loading too is called dbo.INTERNATIONAL_CATALOGNow the scenario is, that if a rule is not meet (in this case if IS_PARENT_PRODUCT = 'Y' but there is no value in the 'PARENT_PRODUCT_ID' the row should be rejected and row should be sent to a reject table.Hmm, this makes me think i need to put some kind of validation in there.Hope this helps-------------------------------------I see.... So can you just do 2 inserts from INITIAL_INTERNATIONAL_CATALOG?insert into INTERNATIONAL_CATALOGselect ....from INITIAL_INTERNATIONAL_CATALOGwhere IS_PARENT_PRODUCT <> 'Y' or PARENT_PRODUCT_ID is not nullinsert into IC_REJECTSselect ...from INITIAL_INTERNATIONAL_CATALOGwhere IS_PARENT_PRODUCT = 'Y' and PARENT_PRODUCT_ID is null |
 |
|
|
|
|
|
|
|