Showing posts with label variable. Show all posts
Showing posts with label variable. Show all posts

Thursday, March 8, 2012

continuous variable prediction

Hi All,

I was wondering if there was a way to specify a range when training a model to predict continuous variables. For instance, the predicted variable can only have a range of 1 - 10.

Thanks

Not really, and it's possible that even if you restrict the training data to the range 1-10 you can end up with predictions outside that range (e.g. if you found x=2y and put 8 as your input).

What you can do is use VBA or Excel MIN/MAX functions on your prediction result. For example you can call

SELECT [MAX]( [MIN]( Predict(MyColumn), 10), 1)

FROM MyModel

PREDICTION JOIN ...

Saturday, February 25, 2012

Containstable variable usage

I have a stored procedure that uses containstable and want to make it a little dynamic so I was going to add a parameter that consist of the column names that needed to be search. But when I add a variable I get an error saying incorrect syntax....

Can you not use a variable as a column list? I have a variable for search criteria and it works fine...

Here is my syntax

containstable([tablename],@.columnlist,@.srch)

I have been looking online and can't seem to find anything that says I can or cannot use a variable.

Column list cannot be replaced by variable. You have to use dynamic SQL to form and execute the SELECT statement if you want to parameterize CONTAINS/CONTAINSTABLE column list.

Contains(@v1, @v2) Is this legal?

I am attempting to perform a contains of one variable string in another.
here is a simple example of what I am attempting to do, this should return
true, but I am not sure if this is a limitation of sql server, that it will
now allow a contains on two datatypes. Any ideas?
declare @.t1 varchar(30),
@.t2 varchar(30)
set @.t1 = 'Te'
set @.t2 = 'Test'
if (Contains(@.t2, @.t1))
print 'true'
else
print 'false'
Thanks.Hi, kapsolas
You probably want to use the CHARINDEX function:
IF CHARINDEX(@.t1,@.t2)<>0 ...
For more informations, see:
http://msdn2.microsoft.com/en-us/library/ms186323.aspx
Razvan|||"kapsolas" <kapsolas@.discussions.microsoft.com> wrote in message
news:F05CD410-BFDD-4627-8308-5B774805A2AA@.microsoft.com...
>I am attempting to perform a contains of one variable string in another.
> here is a simple example of what I am attempting to do, this should return
> true, but I am not sure if this is a limitation of sql server, that it
> will
> now allow a contains on two datatypes. Any ideas?
> declare @.t1 varchar(30),
> @.t2 varchar(30)
> set @.t1 = 'Te'
> set @.t2 = 'Test'
> if (Contains(@.t2, @.t1))
> print 'true'
> else
> print 'false'
> Thanks.
Another solution:
declare @.t1 varchar(30),
@.t2 varchar(30)
set @.t1 = 'Te'
set @.t2 = 'Test'
if @.t2 like '%' + @.t1 + '%'
print 'true'
else
print 'false'|||Raymond,
that is the solution I have implemented. Using the LIKE. I wanted to clean
it up a bit to make it more readable by using the Contains.
I'll play with the char index as recommended in the other post as well.
"Raymond D'Anjou" wrote:

> "kapsolas" <kapsolas@.discussions.microsoft.com> wrote in message
> news:F05CD410-BFDD-4627-8308-5B774805A2AA@.microsoft.com...
> Another solution:
> declare @.t1 varchar(30),
> @.t2 varchar(30)
> set @.t1 = 'Te'
> set @.t2 = 'Test'
> if @.t2 like '%' + @.t1 + '%'
> print 'true'
> else
> print 'false'
>
>|||"kapsolas" <kapsolas@.discussions.microsoft.com> wrote in message
news:F5F39D6F-0723-4EE5-B032-E425A6942D33@.microsoft.com...
> Raymond,
> that is the solution I have implemented. Using the LIKE. I wanted to clean
> it up a bit to make it more readable by using the Contains.
> I'll play with the char index as recommended in the other post as well.
I have no experience with Contains.
This is the information I got in BOL:
...You can use the CONTAINS predicate to search a database for a specific
phrase. Of course, such a query can be written using the LIKE predicate.
However, many forms of CONTAINS provide far more text query capabilities
than can be obtained with LIKE. Additionally, unlike using the LIKE
predicate, a CONTAINS search is always case insensitive...
So, if you are not using the extra "query capabilities" of Contains, I
suggest you use one of the other solutions that you got for this post.
Of course, the best would be to test all solutions with your database and
data to find the one that performs the best.|||Thanks for that piece Raymond.
For now I'll use the LIKE and as soon as I have a bit more time i'll
investigate the contains a bit more.
Thanks for your help
"Raymond D'Anjou" wrote:

> "kapsolas" <kapsolas@.discussions.microsoft.com> wrote in message
> news:F5F39D6F-0723-4EE5-B032-E425A6942D33@.microsoft.com...
> I have no experience with Contains.
> This is the information I got in BOL:
> ...You can use the CONTAINS predicate to search a database for a specific
> phrase. Of course, such a query can be written using the LIKE predicate.
> However, many forms of CONTAINS provide far more text query capabilities
> than can be obtained with LIKE. Additionally, unlike using the LIKE
> predicate, a CONTAINS search is always case insensitive...
> So, if you are not using the extra "query capabilities" of Contains, I
> suggest you use one of the other solutions that you got for this post.
> Of course, the best would be to test all solutions with your database and
> data to find the one that performs the best.
>
>|||> that is the solution I have implemented. Using the LIKE. I wanted to clean
> it up a bit to make it more readable by using the Contains.
I don't know why you think that's cleaner or more readable. I guess for
someone who has never used T-SQL and only used FTS, but I think that'd be a
pretty rare bird.
A

Contains with Var & WildCard

Inside of a stored proc, how would I issue a Contains using a variable and a
wild card, this dosent work
declare @.myvar varchar(50) -- this would be an imput param
set @.myvar = 'hello' -- this would be an imput param
select whatever
from CONTAINS(fieldname, ' " ' + @.myvar + ' *" ')
thanks!Try putting it seperately:
set @.myvar = '"' + @.myvar + '*" '
CONTAINS(fieldname, @.myvar )
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Don Schilling" <fake@.fake.com> schrieb im Newsbeitrag
news:OFlSiDQTFHA.548@.tk2msftngp13.phx.gbl...
> Inside of a stored proc, how would I issue a Contains using a variable and
> a
> wild card, this dosent work
> declare @.myvar varchar(50) -- this would be an imput param
> set @.myvar = 'hello' -- this would be an imput param
> select whatever
> from CONTAINS(fieldname, ' " ' + @.myvar + ' *" ')
> thanks!
>|||constains() only allows literals. so, you want to do the concatenation
outside of the function.
e.g.
@.newvar = quotename(@.myvar+'*','"')
...contains(col,@.newvar)
-oj
"Don Schilling" <fake@.fake.com> wrote in message
news:OFlSiDQTFHA.548@.tk2msftngp13.phx.gbl...
> Inside of a stored proc, how would I issue a Contains using a variable and
> a
> wild card, this dosent work
> declare @.myvar varchar(50) -- this would be an imput param
> set @.myvar = 'hello' -- this would be an imput param
> select whatever
> from CONTAINS(fieldname, ' " ' + @.myvar + ' *" ')
> thanks!
>|||Tried, no luck.
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:evruUQQTFHA.3012@.TK2MSFTNGP14.phx.gbl...
> Try putting it seperately:
> set @.myvar = '"' + @.myvar + '*" '
> CONTAINS(fieldname, @.myvar )
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
>
> "Don Schilling" <fake@.fake.com> schrieb im Newsbeitrag
> news:OFlSiDQTFHA.548@.tk2msftngp13.phx.gbl...
and
>|||Tried, dosent work.
"oj" <nospam_ojngo@.home.com> wrote in message
news:O6nKCXQTFHA.1896@.TK2MSFTNGP14.phx.gbl...
> constains() only allows literals. so, you want to do the concatenation
> outside of the function.
> e.g.
> @.newvar = quotename(@.myvar+'*','"')
> ...contains(col,@.newvar)
> --
> -oj
>
> "Don Schilling" <fake@.fake.com> wrote in message
> news:OFlSiDQTFHA.548@.tk2msftngp13.phx.gbl...
and
>

Friday, February 24, 2012

CONTAINS

Hi,
I would like to perform a search which returns records that are like a
string variable I pass into the query - so to catch spelling mistakes etc.
Eg. string = Commmercial would return Commercial from my reference table.
Could someone recommend the best way to do this. I am using VB.NET and
ADO.NET to execute my sql statement.
Should I use a WHERE CONTAINS clause. If so how does one enable full-text
indexed? I always get this error even using Northwind. "Cannot use a
CONTAINS or FREETEXT predicate on table 'mytable' because it is not
full-text indexed."Have a look at the SOUNDEX command, it may help.
Peter
"11Oppidan" wrote:

> Hi,
> I would like to perform a search which returns records that are like a
> string variable I pass into the query - so to catch spelling mistakes etc.
> Eg. string = Commmercial would return Commercial from my reference table.
> Could someone recommend the best way to do this. I am using VB.NET and
> ADO.NET to execute my sql statement.
> Should I use a WHERE CONTAINS clause. If so how does one enable full-text
> indexed? I always get this error even using Northwind. "Cannot use a
> CONTAINS or FREETEXT predicate on table 'mytable' because it is not
> full-text indexed."
>
>|||Thanks Peter - thats great!
"Peter 'Not Peter The Spate' Nolan"
<PeterNotPeterTheSpateNolan@.discussions.microsoft.com> wrote in message
news:23F80AF0-26B9-48F4-9501-290999F78877@.microsoft.com...
> Have a look at the SOUNDEX command, it may help.
> Peter
> "11Oppidan" wrote:
>

Tuesday, February 14, 2012

Construct Variable Name?

Can you contruct a variable name from another variable? For example, I want the following to PRINT 10

DECLARE @.var1 INT
DECLARE @.var2 INT

SET @.var1 = 10
SET @.var2 = 20

PRINT '@.var' + '1'

This prints the variable name, not the contents of the var. I tried to parse it with square brackets, but no luck.

Thanks,
CarlYou can do this using dynamic SQL, though I'm not sure it would work for the specific PRINT statement in your example.|||Ya, I need a varName in a var. A datatype of VARNAME. in some langs you just parse it correctly and it works, some it won't.

if you substitute EXEC for PRINT, it says you must declare variable 'var1', as you can see it obviously is being declared and interpretted the way it was typed.

Carl|||Actually, dynamic SQL will not work for this example, because the scope of the variables is limited to the procedure in which they are created.

Please explain what you are trying to do, and maybe we can come up with a satisfactory solution.|||I am just trying to simplify the code.

In stead of:

IF @.var1 < @.var2
SET @.var3 = DATEADD(n,GETDATE(), @.var1)
ELSE
SET @.var3 = DATEADD(n,GETDATE(), @.var2)

I was hoping to simply:

SET @.var3 = DATEADD(n,GETDATE(), @.var + @.CurrentVarIndex)

I already know which one I want, @.var1 or @.var2, it's just that I have to IF and have 2 lines to do the work of 1.|||... it's just that I have to IF and have 2 lines to do the work of 1.I've seen worse. Using dynamic SQL or some other hack work around to do this is going to end up making your code more complicated, not simpler.|||I know what you mean regarding the dynamic sql and "the sea of red". can make reviewing your code quite miserable.
Carl