Showing posts with label include. Show all posts
Showing posts with label include. Show all posts

Wednesday, March 21, 2012

hi i want to know how to write stored procedure ..then i have to include (IF condition ) w

hi i want to know how to write stored procedure ..then i have to include (IF condition ) with SP ..

let me this post ..............anybody ????

CREATEPROCEDURE name_of_procedure
-- Add the parameters for the stored procedure here
@.passedparam1 int,
@.passedparam2 smalldatetime

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.

SET NOCOUNTON;

-- Insert statements for procedure here

SELECT [COLOFINTS], [OTHERCOL] FROM MYDBNAME WHERE ([COLOFINTS] = @.passedparam1 AND [DATEENTERED] > @.passedparam2

END

|||

CREATEPROCEDURE name_of_procedure
-- Add the parameters for the stored procedure here
@.passedparam1 int,
@.passedparam2 smalldatetime

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.

SET NOCOUNTON;

-- Insert statements for procedure here

IF @.passedparam2 < GETDATE()

SELECT [COLOFINTS], [OTHERCOL]FROM MYDBNAMEWHERE ([COLOFINTS] = @.passedparam1 AND [DATEENTERED] > @.passedparam2)

ELSE

SELECT [COLOFINTS], [OTHERCOL]FROM MYDBNAMEWHERE [COLOFINTS] = @.passedparam1

END

|||

Just to clarify something that clevesteve wrote, if the IF has > 1 statement, you must wrap it in BEGIN END, for example,

IF @.passedparam2 < GETDATE()
BEGIN
SELECT [COLOFINTS], [OTHERCOL] FROM MYDBNAME WHERE ([COLOFINTS] = @.passedparam1 AND [DATEENTERED] > @.passedparam2)
...some other statement
END
ELSE
BEGIN
SELECT [COLOFINTS], [OTHERCOL] FROM MYDBNAME WHERE [COLOFINTS] = @.passedparam1
..some other statemetn
END

|||

hi thaka for reply

please send me a any tutorial of these stored procudre ...bcz am a beginner of these

|||

You can find many such on the web but here's a start on using T-SQL http://www.sql-server-performance.com/articles/dba/stored_procedures_basics_p1.aspx

For more, just google "sql server how to write stored procedures"

Sql server 2005 also supports writing procs in .net but I have no experience myself with this

Monday, March 12, 2012

Heterogeneous queries error

I'am attempting to modify an SMS 2003 web report to include data from a
linked SQL server. Running the query (report) in Query Analyzer works fine,
however, running the report via the web returns the error:
Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be
set for the connection. This ensures consistent query semantics. Enable these
options and then reissue your query.
Error Number: -2147217900
Source: Microsoft OLE DB Provider for SQL Server
Native Error: 7405
Any ideas how to would fix this?
Inside your proc, add SET ANSI_WARNINGS ON to the beginning of your code.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Chad" <Chad@.discussions.microsoft.com> wrote in message
news:D892A9F1-4184-479E-822F-A6F1939F85A8@.microsoft.com...
> I'am attempting to modify an SMS 2003 web report to include data from a
> linked SQL server. Running the query (report) in Query Analyzer works fine,
> however, running the report via the web returns the error:
> Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be
> set for the connection. This ensures consistent query semantics. Enable these
> options and then reissue your query.
> Error Number: -2147217900
> Source: Microsoft OLE DB Provider for SQL Server
> Native Error: 7405
> Any ideas how to would fix this?
|||I'm not using a stored procedure. SMS 2003 stores the SQL query in the
database as a text field, not as a stored procedure.
"Tibor Karaszi" wrote:

> Inside your proc, add SET ANSI_WARNINGS ON to the beginning of your code.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Chad" <Chad@.discussions.microsoft.com> wrote in message
> news:D892A9F1-4184-479E-822F-A6F1939F85A8@.microsoft.com...
>
>
|||OK, let me re-phrase:
Preceding any other statement in your code, execute that SET command...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Chad" <Chad@.discussions.microsoft.com> wrote in message
news:00AB7DD9-148F-4602-9E46-63C34CA3F576@.microsoft.com...[vbcol=seagreen]
> I'm not using a stored procedure. SMS 2003 stores the SQL query in the
> database as a text field, not as a stored procedure.
> "Tibor Karaszi" wrote:

Heterogeneous queries error

I'am attempting to modify an SMS 2003 web report to include data from a
linked SQL server. Running the query (report) in Query Analyzer works fine,
however, running the report via the web returns the error:
---
Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be
set for the connection. This ensures consistent query semantics. Enable these
options and then reissue your query.
Error Number: -2147217900
Source: Microsoft OLE DB Provider for SQL Server
Native Error: 7405
---
Any ideas how to would fix this?Inside your proc, add SET ANSI_WARNINGS ON to the beginning of your code.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Chad" <Chad@.discussions.microsoft.com> wrote in message
news:D892A9F1-4184-479E-822F-A6F1939F85A8@.microsoft.com...
> I'am attempting to modify an SMS 2003 web report to include data from a
> linked SQL server. Running the query (report) in Query Analyzer works fine,
> however, running the report via the web returns the error:
> ---
> Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be
> set for the connection. This ensures consistent query semantics. Enable these
> options and then reissue your query.
> Error Number: -2147217900
> Source: Microsoft OLE DB Provider for SQL Server
> Native Error: 7405
> ---
> Any ideas how to would fix this?|||I'm not using a stored procedure. SMS 2003 stores the SQL query in the
database as a text field, not as a stored procedure.
"Tibor Karaszi" wrote:
> Inside your proc, add SET ANSI_WARNINGS ON to the beginning of your code.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Chad" <Chad@.discussions.microsoft.com> wrote in message
> news:D892A9F1-4184-479E-822F-A6F1939F85A8@.microsoft.com...
> > I'am attempting to modify an SMS 2003 web report to include data from a
> > linked SQL server. Running the query (report) in Query Analyzer works fine,
> > however, running the report via the web returns the error:
> >
> > ---
> > Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be
> > set for the connection. This ensures consistent query semantics. Enable these
> > options and then reissue your query.
> >
> > Error Number: -2147217900
> > Source: Microsoft OLE DB Provider for SQL Server
> > Native Error: 7405
> > ---
> >
> > Any ideas how to would fix this?
>
>|||OK, let me re-phrase:
Preceding any other statement in your code, execute that SET command...
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Chad" <Chad@.discussions.microsoft.com> wrote in message
news:00AB7DD9-148F-4602-9E46-63C34CA3F576@.microsoft.com...
> I'm not using a stored procedure. SMS 2003 stores the SQL query in the
> database as a text field, not as a stored procedure.
> "Tibor Karaszi" wrote:
> > Inside your proc, add SET ANSI_WARNINGS ON to the beginning of your code.
> >
> > --
> > Tibor Karaszi, SQL Server MVP
> > http://www.karaszi.com/sqlserver/default.asp
> > http://www.solidqualitylearning.com/
> >
> >
> > "Chad" <Chad@.discussions.microsoft.com> wrote in message
> > news:D892A9F1-4184-479E-822F-A6F1939F85A8@.microsoft.com...
> > > I'am attempting to modify an SMS 2003 web report to include data from a
> > > linked SQL server. Running the query (report) in Query Analyzer works fine,
> > > however, running the report via the web returns the error:
> > >
> > > ---
> > > Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be
> > > set for the connection. This ensures consistent query semantics. Enable these
> > > options and then reissue your query.
> > >
> > > Error Number: -2147217900
> > > Source: Microsoft OLE DB Provider for SQL Server
> > > Native Error: 7405
> > > ---
> > >
> > > Any ideas how to would fix this?
> >
> >
> >