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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 if statement

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2011-04-22 : 09:23:36
I need to add an "and" with the if, so if parm like '%1%' and '%0%'

IF @Parameter LIKE '%1%'
BEGIN
INSERT INTO #TempTable (ColumnList)
SELECT ColumnList
FROM OffenderAddressSchool
END



Dave
Helixpoint Web Development
http://www.helixpoint.com

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-04-22 : 09:29:20
IF @Parameter LIKE '%1%' and @Parameter LIKE '%0%'
BEGIN

INSERT INTO #TempTable (ColumnList)
SELECT ColumnList
FROM OffenderAddressSchool
END

Jim



Everyday I learn something that somebody else already knew
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-22 : 09:29:21
IF @Parameter LIKE '%1%' AND @Parameter LIKE '%0%'
BEGIN
INSERT INTO #TempTable (ColumnList)
SELECT ColumnList
FROM OffenderAddressSchool
END



Deadly 1 second sniper!
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-04-22 : 09:30:27
You're just way too slow! Get that Yak blaster out!

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-04-22 : 09:31:12
That's pretty fast on the draw!

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-22 : 09:32:36
There's a thread somewhere with a zero-second snipe, I'll try and find it.
Go to Top of Page

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2011-04-22 : 09:34:01
too funny. Thanx guys

Dave
Helixpoint Web Development
http://www.helixpoint.com
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-22 : 09:53:10
Found it: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=75845

There are about 90 simultaneous posts, but that's the only acknowledged snipe I could find in that bunch.
Go to Top of Page

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2011-04-22 : 09:54:10
This does not seem to be getting any data. What am I doing wrong?

DECLARE @Parameter as varchar(100)
set @Parameter = '1,2,5'

CREATE TABLE #TempTable (
street char(100),
city char(50) )

IF @Parameter LIKE '%1%' AND @Parameter LIKE '%0%'
BEGIN
INSERT INTO #TempTable (street, city)
SELECT street, city
FROM OffenderSchoolInformation
END

IF @Parameter LIKE '%4%' AND @Parameter LIKE '%0%'
BEGIN
INSERT INTO #TempTable (street, city)
SELECT street, city
FROM OffenderEmployment
END

IF @Parameter LIKE '%5%' AND @Parameter LIKE '%0%'
BEGIN
INSERT INTO #TempTable (street, city)
SELECT street, city
FROM OffenderSchoolInformation
END

select * from #tempTable
drop table #tempTable

Dave
Helixpoint Web Development
http://www.helixpoint.com
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-22 : 09:56:32
Well, you're specifying AND LIKE '%0%', but the parameter you're using doesn't contain a 0. Maybe you need OR instead of AND.
Go to Top of Page

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2011-04-22 : 09:57:54
Crap. needed an OR

Dave
Helixpoint Web Development
http://www.helixpoint.com
Go to Top of Page
   

- Advertisement -