April 18, 2013 at 10:01 am
Table with Values
CREATE TABLE InitialData
(
recno int PRIMARY KEY,
Dept Varchar(30),
entry_name Varchar(50),
entry varchar(500),
orgID int
)
INSERT INTO InitialData Values
(1, 'Marketing', 'Timesservedstartdate', '8/6/2012 12:00:00 AM', 1234),
(2, 'Sales', 'Timesservedstartdate', '8/6/2012 12:00:00 AM', 1234),
(3, 'Development', 'Reporting', 'Somevalue', 1234),
(4, 'HumanResources', 'Reporting', '1', 1234),
(5, 'Support', 'Reporting', '1', 1234);
Trying to test the condition that i developed...i want to compare all the rows with the entry value '1'. Any values other than 1 should be equal to 0 is the condition. NOTE: entry is a varchar column
IF (SELECT COALESCE((SELECT dI.[entry] FROM dbo.InitialData AS dI WITH(NOLOCK) WHERE dI.Dept = 'Reporting'
AND dI.entry_name = 'PledgeRequireBatch'
AND dI.orgID = 1234
AND dI.[entry] <> 1), 0)) = 1
BEGIN
Select * from InitialData
END
ELSE
Select TOP 1 * FROM InitialData
I am getting the else statement result always but that is not what i want
1MarketingTimesservedstartdate8/6/2012 12:00:00 AM1234
--Pra:-):-)--------------------------------------------------------------------------------
April 18, 2013 at 10:51 am
Duplicate thread. direct all replies here. http://www.sqlservercentral.com/Forums/Topic1443974-391-1.aspx
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 18, 2013 at 11:00 am
Well, yes but i wanted to delete this.. dont know how.. How do i do it??
--Pra:-):-)--------------------------------------------------------------------------------
April 18, 2013 at 11:04 am
prathibha_aviator (4/18/2013)
Well, yes but i wanted to delete this.. dont know how.. How do i do it??
You can't. No big deal. It is best if somebody lets other know it is duplicate so you don't end up with answers in both threads.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy