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 |
|
sharona
Yak Posting Veteran
75 Posts |
Posted - 2011-07-08 : 08:59:23
|
| how do i get multiple like values from my where statementi tried in but it didnt work. not sure of the syntax.i want to get the following values as wellfixedfloat, purchaseprice, roll etc.select distinct o.xtype AS TYPE, o.name AS STORED_PROC, o.crdate AS CREATE_DATE,'ActualTradeDate' AS FIELD_NAMEfrom syscomments c join sysobjects o on c.id = o.id where c.text like ('%ActualTradeDate%')order by o.xtype, o.name |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-08 : 09:26:57
|
| where c.text like ('%ActualTradeDate%')or c.text like ('%fixedfloat%')or c.text like ('%purchaseprice%')or c.text like ('%roll %')order by o.xtype, o.namemaybe you want "and" instead of "or" - it's not clear from the question.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
sharona
Yak Posting Veteran
75 Posts |
Posted - 2011-07-08 : 09:33:29
|
| thanks that is what i did, i thought i could use an in statement. thanks |
 |
|
|
sharona
Yak Posting Veteran
75 Posts |
Posted - 2011-07-08 : 09:33:30
|
| thanks that is what i did, i thought i could use an in statement. thanks |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-08 : 09:39:36
|
| Nope - not with a like.you canwith cte as(select s = '%ActualTradeDate%'union allselect s = '%fixedfloat%'union allselect s = '%purchaseprice%'union allselect s = '%roll%')select distinct o.xtype AS TYPE, o.name AS STORED_PROC, o.crdate AS CREATE_DATE,'ActualTradeDate' AS FIELD_NAMEfrom syscomments c join sysobjects o on c.id = o.id join cteon c.text like cte.sorder by o.xtype, o.name==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
sharona
Yak Posting Veteran
75 Posts |
Posted - 2011-07-08 : 10:18:41
|
| not sure where to place that this is my sp where would i place and what is the syntax, bit confusedwith cte as(select s = 'ActualTradeDate'union allselect s = 'Actual Trade Date'union allselect s = 'Fixedfloat'union allselect s = 'Purchaseprice'union allselect s = 'Roll'union allselect s = 'Rolldate'union allselect s = 'ISIN'union allselect s = 'Cusip'union allselect s = 'Bloomberg')CREATE TABLE #RPTLIST3663(TYPE VARCHAR(2),STORED_PROC VARCHAR(255), CREATE_DATE DATETIME,FIELD_NAME VARCHAR(255))INSERT INTO #RPTLIST3663select distinct o.xtype AS TYPE, o.name AS STORED_PROC, o.crdate AS CREATE_DATE,CASE WHEN c.text like ('%ActualTradeDate%') THEN 'ActualTradeDate'WHEN c.text like ('%Actual Trade Date%') THEN 'Actual Trade Date'WHEN c.text like ('%Fixedfloat%') THEN 'Fixedfloat'WHEN c.text like ('%Purchaseprice%') THEN 'Purchaseprice'WHEN C.text like ('%Roll%') THEN 'Roll'WHEN c.text like ('%Rolldate%') THEN 'Rolldate'WHEN C.text like ('%ISIN%') THEN 'ISIN'WHEN c.text like ('%Cusip%') THEN 'Cusip'WHEN c.text like ('%Bloomberg%') THEN 'Bloomberg' END AS FIELD_NAMEfrom syscomments c join sysobjects o on c.id = o.id where c.text like ('%ActualTradeDate%')OR c.text like ('%Actual Trade Date%') OR c.text like ('%Fixedfloat%') OR c.text like ('%Purchaseprice%') OR c.text like ('%Roll%')OR c.text like ('%Rolldate%')OR c.text like ('%ISIN%')OR c.text like ('%Cusip%')OR c.text like ('%Bloomberg%')order by o.xtype, o.name |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-08 : 10:41:12
|
| with cte as(select FIELD_NAME = 'ActualTradeDate', seq = 1union allselect FIELD_NAME = 'Actual Trade Date', 2union allselect FIELD_NAME = 'Fixedfloat', 3union allselect FIELD_NAME = 'Purchaseprice', 4union allselect FIELD_NAME = 'Roll', 5union allselect FIELD_NAME = 'Rolldate', 6union allselect FIELD_NAME = 'ISIN', 7union allselect FIELD_NAME = 'Cusip', 8union allselect FIELD_NAME = 'Bloomberg', 9) ,cte2 as(select distinct max(o.xtype) AS TYPE, o.name AS STORED_PROC, max(o.crdate) AS CREATE_DATE,min(seq) AS seqfrom syscomments cjoin sysobjects oon c.id = o.id join cteon c.text like '%' + cte.FIELD_NAME + '%'group by o.name)INSERT INTO #RPTLIST3663select cte.TYPE, cte.STORED_PROC, cte.CREATE_DATE,cte2.FIELD_NAMEfrom ctejoin cte2on cte.seq = cte2.seqbut it might be better to have the fields as a table variabledeclare @fields table (FIELD_NAME varchar(50), seq int identity)insert @fields ((FIELD_NAME)values ('ActualTradeDate'),('Actual Trade Date'),('Fixedfloat'),('Purchaseprice'),('Roll'),('Rolldate'),('ISIN'),('Cusip'),('Bloomberg');with cte2 as(select distinct max(o.xtype) AS TYPE, o.name AS STORED_PROC, max(o.crdate) AS CREATE_DATE,min(seq) AS seqfrom syscomments cjoin sysobjects oon c.id = o.id join @fields cteon c.text like '%' + cte.FIELD_NAME + '%'group by o.name)INSERT INTO #RPTLIST3663select cte.TYPE, cte.STORED_PROC, cte.CREATE_DATE,cte2.FIELD_NAMEfrom @fields ctejoin cte2on cte.seq = cte2.seqNote - this will only give the value for the lowest seq for the name found like your code. Easy to change it to give them all as seperate entries or a csv list.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|