| Author |
Topic |
|
Fu
Starting Member
23 Posts |
Posted - 2005-11-16 : 15:23:22
|
| set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgocreate FUNCTION [dbo].[search](@art varchar,@cd varchar,@tra varchar,@gen varchar,@cdate datetime,@label varchar) RETURNS @result TABLE(Artist varchar(100),CDTitle varchar(100),Track varchar(100),CDtype varchar(100),CDDate datetime, Label varchar(100))ASBEGINIF @art <>'/'INSERT INTO @result SELECT dbo.CD.CDCoverURL AS ' ', dbo.CD.CDTitle AS 'CD Title',cd.cdtype as 'Section', convert(varchar,cd.cddate,106) as 'Release Date', dbo.Label.Label, dbo.Shelf.Shelf FROM artist,cd,label,shelf,cdtrack,artisttrack,track WHERE artist.artistid=artisttrack.artistid and cd.cdid=cdtrack.cdid and track.trackid=cdtrack.trackid and label.labelid=cd.labelid and shelf.shelfid=cd.shelfid and artisttrack.trackid=track.trackid and artist.artist=@art Group by dbo.CD.CDCoverURL, dbo.CD.CDTitle, dbo.CD.CDType, dbo.CD.CDDate, dbo.Label.Label, dbo.Shelf.Shelf if @cd <>'/'insert into @result SELECT dbo.CD.CDCoverURL AS ' ', dbo.CD.CDTitle AS 'CD Title',cd.cdtype as 'Section', convert(varchar,cd.cddate,106) as 'Release Date', dbo.Label.Label, dbo.Shelf.ShelfFROM artist,cd,label,shelf,cdtrack,artisttrack,trackwhere artist.artistid=artisttrack.artistidand cd.cdid=cdtrack.cdid and track.trackid=cdtrack.trackid and label.labelid=cd.labelidand shelf.shelfid=cd.shelfid and artisttrack.trackid=track.trackid and cd.cdtitle=@cdGroup by dbo.CD.CDCoverURL, dbo.CD.CDTitle, dbo.CD.CDType, dbo.CD.CDDate, dbo.Label.Label, dbo.Shelf.Shelf if @tra <> '/'insert into @result SELECT dbo.CD.CDCoverURL AS ' ', dbo.CD.CDTitle AS 'CD Title',cd.cdtype as 'Section', convert(varchar,cd.cddate,106) as 'Release Date', dbo.Label.Label, dbo.Shelf.ShelfFROM artist,cd,label,shelf,cdtrack,artisttrack,trackwhere artist.artistid=artisttrack.artistidand cd.cdid=cdtrack.cdid and track.trackid=cdtrack.trackid and label.labelid=cd.labelidand shelf.shelfid=cd.shelfid and artisttrack.trackid=track.trackid and track.track=@traGroup by dbo.CD.CDCoverURL, dbo.CD.CDTitle, dbo.CD.CDType, dbo.CD.CDDate, dbo.Label.Label, dbo.Shelf.Shelf if @gen <>'/'insert into @result SELECT dbo.CD.CDCoverURL AS ' ', dbo.CD.CDTitle AS 'CD Title',cd.cdtype as 'Section', convert(varchar,cd.cddate,106) as 'Release Date', dbo.Label.Label, dbo.Shelf.ShelfFROM artist,cd,label,shelf,cdtrack,artisttrack,trackwhere artist.artistid=artisttrack.artistidand cd.cdid=cdtrack.cdid and track.trackid=cdtrack.trackid and label.labelid=cd.labelidand shelf.shelfid=cd.shelfid and artisttrack.trackid=track.trackid and cd.cdtype=@genGroup by dbo.CD.CDCoverURL, dbo.CD.CDTitle, dbo.CD.CDType, dbo.CD.CDDate, dbo.Label.Label, dbo.Shelf.Shelf if @cdate<>'01/01/1900'insert into @result SELECT dbo.CD.CDCoverURL, dbo.CD.CDTitle, dbo.CD.CDType, dbo.CD.CDDate, dbo.Label.Label, dbo.Shelf.ShelfFROM artist,cd,label,shelf,cdtrack,artisttrack,trackwhere artist.artistid=artisttrack.artistidand cd.cdid=cdtrack.cdid and track.trackid=cdtrack.trackid and label.labelid=cd.labelidand shelf.shelfid=cd.shelfid and artisttrack.trackid=track.trackid and cd.cddate=@cdateGroup by dbo.CD.CDCoverURL, dbo.CD.CDTitle, dbo.CD.CDType, dbo.CD.CDDate, dbo.Label.Label, dbo.Shelf.Shelf if @label<>'/'insert into @result SELECT dbo.CD.CDCoverURL, dbo.CD.CDTitle, dbo.CD.CDType, dbo.CD.CDDate, dbo.Label.Label, dbo.Shelf.ShelfFROM artist,cd,label,shelf,cdtrack,artisttrack,trackwhere artist.artistid=artisttrack.artistidand cd.cdid=cdtrack.cdid and track.trackid=cdtrack.trackid and label.labelid=cd.labelidand shelf.shelfid=cd.shelfid and artisttrack.trackid=track.trackid and label.label=@labelGroup by dbo.CD.CDCoverURL, dbo.CD.CDTitle, dbo.CD.CDType, dbo.CD.CDDate, dbo.Label.Label, dbo.Shelf.Shelf returnend---------------------------------------------------------------------upon running executing this function with valid values i am not getting any results.anything is wrong?thank you, |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-11-16 : 16:00:58
|
| "anything is wrong?"None of your "insert into @result SELECT ... " found any rows to process?Kristen |
 |
|
|
Fu
Starting Member
23 Posts |
Posted - 2005-11-16 : 16:07:07
|
| yes none and that's weird because i have already made sure that the parameter value let's say for cdtitle is valid. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-11-16 : 17:36:53
|
I think you need to look at how you declared your VARCHAR input parameters. I doubt that you are getting what you expected. See what happend with the code below:create FUNCTION [dbo].[search] ( @art varchar, @cd varchar, @tra varchar, @gen varchar, @label varchar)returns table asreturn(select art = @art, cd = @cd , tra = @tra , gen = @gen , label = @label )goselect *from [dbo].[search]('12345','23456','34567','45678','56789')art cd tra gen label ---- ---- ---- ---- ----- 1 2 3 4 5(1 row(s) affected)CODO ERGO SUM |
 |
|
|
Fu
Starting Member
23 Posts |
Posted - 2005-11-18 : 03:49:37
|
| I have modified the varchar variables apropriately but still getting the following errorMsg 241, Level 16, State 1, Line 1Conversion failed when converting datetime from character string.still am getting this error |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-11-18 : 07:59:38
|
Why didn't you mention that you are getting this error before now?quote: Originally posted by Fu I have modified the varchar variables apropriately but still getting the following errorMsg 241, Level 16, State 1, Line 1Conversion failed when converting datetime from character string.still am getting this error
CODO ERGO SUM |
 |
|
|
Fu
Starting Member
23 Posts |
Posted - 2005-11-18 : 08:10:48
|
| i wasnt getting it until i modified the varchar variables. but what does it have to do with varchar variables? |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-11-18 : 09:38:51
|
| Parameter 5 in your code which calls the function is not a valid date, or is not in an appropriate format.Use a variable of type date / datetime (such as NOW() in VB) or present a string in one of these formats only: 'yyyyddmm', 'yyyyddmm hh:mm:ss.mmm' or 'yyyy-dd-mmThh:mm:ss.mmm'Kristen |
 |
|
|
Fu
Starting Member
23 Posts |
Posted - 2005-11-18 : 10:15:12
|
| select *from dbo.search('/','/','/','new age','1900-01-01','/')----------------------------------------------------------------Msg 241, Level 16, State 1, Line 1Conversion failed when converting datetime from character string.----------------------------------------------------------------is that what you mean?in vb.net i am having an issue. date should be inserted via a TextBox so in case it was empty the oledbparameter should be passed to sql in order be correctly processed. -----------------------------------------If ReleaseDate.Text = "" Then op5.Value = "1900-01-01" Else : op5.Value = result End If |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-11-18 : 11:41:43
|
| "is that what you mean?"Yes. Your string date '1900-01-01' does not confirm to one of the formats I listed aboveEDIT: Actually, in the case of Day=01 and Month=01 the date can be interpreted any way round, so its probably not an issue, but you should still avoid this format.Kristen |
 |
|
|
Fu
Starting Member
23 Posts |
Posted - 2005-11-18 : 11:48:22
|
| and the outlet is?there wont be any problem using yyyyddmmi will try :Dbtw thank yousory i just tried it and it didnt workselect * from dbo.search('/','/','/','new age','20051111','/') |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-11-18 : 11:52:25
|
| RETURNS @result TABLE(Artist varchar(100),CDTitle varchar(100),Track varchar(100),CDtype varchar(100),CDDate datetime, Label varchar(100))...INSERT INTO @result SELECT dbo.CD.CDCoverURL AS ' ', dbo.CD.CDTitle AS 'CD Title',cd.cdtype as 'Section', convert(varchar,cd.cddate,106) as 'Release Date', dbo.Label.Label, dbo.Shelf.ShelfWell, your columns don't match up on this INSERT, I haven't checked the othersKristen |
 |
|
|
Fu
Starting Member
23 Posts |
Posted - 2005-11-18 : 11:55:59
|
| this means i should remove the convert [date formaat] no? |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-11-18 : 12:00:26
|
| No, it means you should get your INSERT columns in the same order as the Table's definition !!!!Kristen |
 |
|
|
|
|
|