Friday, February 24, 2012

How to use CLR Stored Procedures in Reporting Services?

Hi there.

As subject metioned,I got a problem.

I have a CLR Stored Procedures it works fine in Sql Server Management Studio,but when excuting the stored procedure in Reporting Services Query Builder window(Visual Studio Reporting Services Project),I got a error message "The stored procedure <stored_procedure_name> doesn't exist".

so how to resolve this problem?

my env : SQL Server 2005 , Visual Studio 2005

many thanks.

The CLR stored procedure is attached to a specific database. Make sure that you are connecting to the correct database when you initialize the data source you are using. I have gotten CLR stored procedures to work so I know they will work in Reporting Services.|||

Maybe i got something wrong,i'll check it.

Now i use a T-SQL Stored Procedure as a wrapper to call the CLR one,and it works fine.

thanks and best regards :D

|||

Hi,

I have the same problem.

I also tried with the t-sql stored procedure as wrapper, but when executing it, I get the error

"The transaction context is already in use in another session".

This time the error appears executing the stored procedure from Sql Server Management Studio too.

So I'm giving up. Unless somebody has some suggestions.

Bye.

How to use CLR Stored Procedures in Reporting Services?

Hi there.

As subject metioned,I got a problem.

I have a CLR Stored Procedures it works fine in Sql Server Management Studio,but when excuting the stored procedure in Reporting Services Query Builder window(Visual Studio Reporting Services Project),I got a error message "The stored procedure <stored_procedure_name> doesn't exist".

so how to resolve this problem?

my env : SQL Server 2005 , Visual Studio 2005

many thanks.

The CLR stored procedure is attached to a specific database. Make sure that you are connecting to the correct database when you initialize the data source you are using. I have gotten CLR stored procedures to work so I know they will work in Reporting Services.|||

Maybe i got something wrong,i'll check it.

Now i use a T-SQL Stored Procedure as a wrapper to call the CLR one,and it works fine.

thanks and best regards :D

|||

Hi,

I have the same problem.

I also tried with the t-sql stored procedure as wrapper, but when executing it, I get the error

"The transaction context is already in use in another session".

This time the error appears executing the stored procedure from Sql Server Management Studio too.

So I'm giving up. Unless somebody has some suggestions.

Bye.

How to use CLR security ..Impersonation to access external resources?

I want to Access External resources inside the CLR Code... But I am getting Security Exception

I have marked Assembly with External Access... here is the way I am doing..

I read articles and MSDN .. everywhere is written to use impersonation like

using (WindowsIdentity id = SqlContext.WindowsIdentity)

{

WindowsImpersonationContext c = id.Impersonate();

//perform operations with external resources and then undo

c.Undo();

}

In above case .. I tried both Windows Authentications and SQL Authentications ...

In case of Windows.. I am have a domain login to logon to my pc, while sql server is at another machine and Active directory is at different machine .. when connect to Database .. it says cannot find user Domainname\user

and the SqlContext.WindowsIdentity is always null or it has exception User.Toked thew Security exception.

After that .. I tried to user custome Identity .. using IIdentity =GenericIdentity("UserName","Windows");

But there is now difference .. still same exception .. as given below..

[Microsoft.SqlServer.Server.SqlProcedure]

public static void MyProcedure()

{

Process[] p = Process.GetProcessesByName("YPager"); //Yahoo messanger exe .. a process

p[0].kill();

}

A .NET Framework error occurred during execution of user defined routine or aggregate 'MyProcedure': System.Security.SecurityException: Request failed.

System.Security.SecurityException:

at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)

at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)

at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)

at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)

at DatFileGenerator.StoredProcedures.'MyProcedure'()

.

No rows affected.

(0 row(s) returned)

@.RETURN_VALUE =

Finished running [dbo].['MyProcedure'].

How could I go ahead... what I should do to accompilsh the task...

Kindlly .. suggestions and ideas..

Thanks,

Muna

few things that might help you...

first, there is this blog post, http://blogs.msdn.com/dataaccess/archive/2006/01/25/517495.aspx

second, YOU MUST CONNECT TO DATABASE USING WINDOWS AUTHENTICATION FOR IMPERSONATION TO WORK

third, try using the UNSAFE PERMISSION SET instead of external access

fourth, here is an impersonation sample from my upcoming SQLCLR book:

public partial class StoredProcedures

{

[Microsoft.SqlServer.Server.SqlProcedure()]

public static void uspExternalConnection()

{

WindowsIdentity newIdentity = null;

WindowsImpersonationContext newContext = null;

try

{

//impersonate the caller

newIdentity = SqlContext.WindowsIdentity;

newContext = newIdentity.Impersonate();

if (newContext != null)

{

using (SqlConnection oConn =

new SqlConnection("Server=.\\sqlexpress;" +

"Integrated Security=true;"))

{

SqlCommand oCmd = new SqlCommand("SELECT * FROM " +

"AdventureWorks.HumanResources.Employee", oConn);

oConn.Open();

SqlDataReader oRead =

oCmd.ExecuteReader(CommandBehavior.CloseConnection);

//revent security context

newContext.Undo();

//return results

SqlContext.Pipe.Send(oRead);

}

}

else

{

throw new Exception("user impersonation has failed");

}

}

catch (SqlException ex)

{

SqlContext.Pipe.Send(ex.Message.ToString());

}

finally

{

if (newContext != null)

{

newContext.Undo();

}

}

}

};

|||

Hi Muna,

It looks like your impersonation call and attempt to access external resources are working - the problem is with what you're trying to done from an external_access assembly. Finding and killing an external process is not allowed in external_access assemblies, so you'll need to use UNSAFE instead. The exception shows that you're hitting a CodeAccessSecurity violation, as stated in the clr documentation on the Process class: http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.aspx

"This class contains a link demand and an inheritance demand at the class level that applies to all members. A SecurityException is thrown when either the immediate caller or the derived class does not have full-trust permission. For details about security demands, see Link Demands and Inheritance Demands."

Steven

|||

Thank you for the for helping me out ....

I am able to connect to database, inserting, updating and pulling out data from there, using Windows Authentication....

As well .. I have written data to a file (on filesystem)

All it work fine But when I try to use the code to kill a process .. It generate Exception

Here is code which cause Exception....

public partial class StoredProcedures
{

public partial class StoredProcedures
{

[Microsoft.SqlServer.Server.SqlProcedure()]

public static void TestSecurity()
{

WindowsIdentity newIdentity = null;
WindowsImpersonationContext newContext = null;
try
{
//impersonate the caller
newIdentity = SqlContext.WindowsIdentity;

newContext = newIdentity.Impersonate();
if (newContext != null)
{
using (SqlConnection oConn = new SqlConnection(@."Data Source=MyComputerName\SQLEXPRESS;Initial Catalog=DataBaseName;Integrated Security=True;"))
{
SqlCommand oCmd = new SqlCommand("SELECT * FROM " +"AdventureWorks.HumanResources.Employee", oConn);
oConn.Open();
SqlDataReader oRead = oCmd.ExecuteReader(CommandBehavior.CloseConnection);

Process[] p = Process.GetProcessesByName("YPager"); //Yahoo messanger exe .
p[0].kill();

//revent security context
newContext.Undo();
//return results
SqlContext.Pipe.Send(oRead);
}
}
else
{
throw new Exception("user impersonation has failed");
}
}
catch (SqlException ex)
{
SqlContext.Pipe.Send(ex.Message.ToString());
}
finally
{
if (newContext != null)
{
newContext.Undo();
}
}
}
}
};

The Problem is with killing external (windows) process from SQL App

SQL Server AppDomain

About impersonating the user.... I am getting Exception

//impersonate the caller
during debuggin At this line when I check in wach window

newIdentity = SqlContext.WindowsIdentity;

It has following information....

AuthenticationType = 'SqlContext.WindowsIdentity.AuthenticationType' threw an exception of type 'System.UnauthorizedAccessException'

Groups = {System.Security.Principal.IdentityReferenceCollection}

ImpersonationLevel = Impersonation

IsAnonymous = false

IsAuthenticated = true

IsGuest = false

IsSystem=false

Name="DomainName\myLoginName"

Owner = {S-1-5-21-15454545467-37684546461-44646464642-1176}

Token="2342"

User = {S-1-5-21-1878703567-3768572861-466091742-1176}



hmmmm Where I am going wrong?

|||Hi Steven,
Thank you for helping me out...
I have used the attribute as following..

[assembly: IsolatedStorageFilePermission(SecurityAction.RequestMinimum, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]

public partial class

StoredProcedures
{

public partial class StoredProcedures


{

[Microsoft.SqlServer.Server.SqlProcedure()]


public static void TestSecurity()
{


WindowsIdentity newIdentity = null;
WindowsImpersonationContext

newContext = null;
try
{


//impersonate the caller
newIdentity =

SqlContext.WindowsIdentity;

newContext =

newIdentity.Impersonate();
if (newContext !=

null)
{
using (SqlConnection oConn = new

SqlConnection(@."Data Source=MyComputerName\SQLEXPRESS;Initial

Catalog=DataBaseName;Integrated Security=True;"))

{
SqlCommand oCmd = new

SqlCommand("SELECT * FROM " +"AdventureWorks.HumanResources.Employee",

oConn);
oConn.Open();


SqlDataReader oRead =

oCmd.ExecuteReader(CommandBehavior.CloseConnection);

Process[] p = Process.GetProcessesByName("YPager");

//Yahoo messanger exe .

p[0].kill();

//revent security

context
newContext.Undo();


//return results


SqlContext.Pipe.Send(oRead);
}


}
else
{
throw new

Exception("user impersonation has failed");
}


}
catch (SqlException ex)
{


SqlContext.Pipe.Send(ex.Message.ToString());
}


finally
{
if (newContext !=

null)
{


newContext.Undo();
}
}
}


}
};

It is helping me out to kill the process but still exception
ExitCode = 'p[0].ExitCode' threw an exception of type 'System.InvalidOperationException'

Thanks
|||

Have you tried killing YPager and doing p[0].ExitCode outside SQL Server in a simple console app? The documentation on Process.ExitCode (http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.exitcode.aspx) says the following:

Exceptions

Exception type

Condition

InvalidOperationException

The process has not exited.

-or-

The process Handle is not valid.

If it works outside SQL Server. Can you post the complete exception that you are getting from inside SQL?

Thanks,

-Vineet.

|||Hi Vineet,

For better understanding here are some facts

ComputerName = ProductionPC

Application Name = TestApplication

Here is execution .code..

Auto-attach to process '[3224] [SQL] ProductionPC' on machine 'ProductionPC' succeeded.
Running [dbo].[TestSecurity].

The thread 'ProductionPC\sqlexpress [55]' (0x8a0) has exited with code 0 (0x0).
The thread 'ProductionPC\sqlexpress [55]' (0x8a0) has exited with code 0 (0x0).
The thread 'ProductionPC\sqlexpress [55]' (0x8a0) has exited with code 0 (0x0).
'sqlservr.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sqlservr.exe' (Managed): Loaded 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\SqlAccess.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sqlservr.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sqlservr.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sqlservr.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\System.Transactions\2.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sqlservr.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Security\2.0.0.0__b03f5f7f11d50a3a\System.Security.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Auto-attach to process '[3224] sqlservr.exe' on machine 'ProductionPC' succeeded.
'sqlservr.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'sqlservr.exe' (Managed): Loaded 'TestApplication', Symbols loaded.
'sqlservr.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', No symbols loaded.
EmployeeID NationalIDNumber ContactID LoginID ManagerID Title BirthDate MaritalStatus Gender HireDate SalariedFlag VacationHours SickLeaveHours CurrentFlag rowguid ModifiedDate
-- - -- - -- -- -- - -- - -- -- -- --
No rows affected.
(1 row(s) returned)
@.RETURN_VALUE =
Finished running [dbo].[TestSecurity].
The thread 'ProductionPC\sqlexpress [55]' (0x8a0) has exited with code 0 (0x0).
The program '[3224] [SQL] ProductionPC: ProductionPC\sqlexpress' has exited with code 0 (0x0).
The program '[3224] sqlservr.exe: Managed' has exited with code 259 (0x103).

Taking look on object P (instance holding the process to kill ) in watch window.. gives following iformation

- p {Dimensions:[1]} System.Diagnostics.Process[]
- [0] {System.Diagnostics.Process (DAP)} System.Diagnostics.Process
+ base {System.Diagnostics.Process (DAP)} System.ComponentModel.Component {System.Diagnostics.Process}
BasePriority 8 int
EnableRaisingEvents false bool
+ ExitCode 'p[0].ExitCode' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException}
+ ExitTime 'p[0].ExitTime' threw an exception of type 'System.InvalidOperationException' System.DateTime {System.InvalidOperationException}
+ Handle 3524 System.IntPtr
HandleCount 439 int
HasExited false bool
Id 2576 int
MachineName "." string
+ MainModule {System.Diagnostics.ProcessModule (DAP.exe)} System.Diagnostics.ProcessModule
+ MainWindowHandle 0 System.IntPtr
MainWindowTitle "" string
+ MaxWorkingSet 1413120 System.IntPtr
+ MinWorkingSet 204800 System.IntPtr
+ Modules {System.Diagnostics.ProcessModuleCollection} System.Diagnostics.ProcessModuleCollection
NonpagedSystemMemorySize 30440 int
NonpagedSystemMemorySize64 30440 long
PagedMemorySize 16273408 int
PagedMemorySize64 16273408 long
PagedSystemMemorySize 75080 int
PagedSystemMemorySize64 75080 long
PeakPagedMemorySize 37670912 int
PeakPagedMemorySize64 37670912 long
PeakVirtualMemorySize 132988928 int
PeakVirtualMemorySize64 132988928 long
PeakWorkingSet 22728704 int
PeakWorkingSet64 22728704 long
PriorityBoostEnabled true bool
PriorityClass Normal System.Diagnostics.ProcessPriorityClass
PrivateMemorySize 16273408 int
PrivateMemorySize64 16273408 long
+ PrivilegedProcessorTime {00:00:00.8437500} System.TimeSpan
ProcessName "DAP" string
+ ProcessorAffinity 1 System.IntPtr
Responding true bool
SessionId 0 int
+ StandardError 'p[0].StandardError' threw an exception of type 'System.InvalidOperationException' System.IO.StreamReader {System.InvalidOperationException}
+ StandardInput 'p[0].StandardInput' threw an exception of type 'System.InvalidOperationException' System.IO.StreamWriter {System.InvalidOperationException}
+ StandardOutput 'p[0].StandardOutput' threw an exception of type 'System.InvalidOperationException' System.IO.StreamReader {System.InvalidOperationException}
+ StartInfo {System.Diagnostics.ProcessStartInfo} System.Diagnostics.ProcessStartInfo
+ StartTime {7/28/2006 11:14:44 PM} System.DateTime
SynchronizingObject null System.ComponentModel.ISynchronizeInvoke
+ Threads {System.Diagnostics.ProcessThreadCollection} System.Diagnostics.ProcessThreadCollection
+ TotalProcessorTime {00:00:03.7031250} System.TimeSpan
+ UserProcessorTime {00:00:02.8593750} System.TimeSpan
VirtualMemorySize 132988928 int
VirtualMemorySize64 132988928 long
WorkingSet 9736192 int
WorkingSet64 9736192 long
+ Static members
+ Non-Public members

Thanks|||

Muna & Steve,

I marked steve's reply as correct...(which he was correct, much better than my response)...NOW HOW CAN I MARK A REPLY AS AN ANSWER TO A THREAD I DID NOT START LOL!

|||Hi

Derek

Thank you for your comments...
I am really glad to know that you are very generous in addition to be a developer (Engineer /Manager)

You are right that steve's reply is more helping...and I will mark it too..
But I am having few exceptions as posted above... I want to make it working so that some one else can get somplete solution from here too..

I will wornder if you guys could help me out to resolve these exceptions related issues.

Thanks

|||

Hi,

Try this:

Process[] p = Process.GetProcessesByName("YahooMessenger"); //Yahoo messanger exe .

p[0].EnableRaisingEvents = true;

p[0].Kill();

p[0].WaitForExit();

int ExitCode = p[0].ExitCode;

This is explained in the documentation for Process.ExitCode at http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.exitcode.aspx . I think i had a link to this documentation in my previous post as well :)

Thanks,

-Vineet.

|||

Hi Vineet,

I could not take a look on your last reply ..(on weekend went away ...)

As you refere to your previous post's links... yes, I worked on that .. as well as on the suggestions from other friends...

Till right now What I got is ..

1- I have marked assembly Unsafe, It allow to kill the process ,

when I call the SP from Visual Studio... even there are exceptions .. but still process if killed

2 - when same SP is called from SQL server, exception is thrown, I am using integrated connection...

Msg 6522, Level 16, State 1, Procedure TestSecurity, Line 0

A .NET Framework error occurred during execution of user defined routine or aggregate 'TestSecurity':

System.ComponentModel.Win32Exception: Access is denied

System.ComponentModel.Win32Exception:

at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited)

at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited)

at System.Diagnostics.Process.OpenProcessHandle()

at System.Diagnostics.Process.set_EnableRaisingEvents(Boolean value)

at StoredProcedures.TestSecurity()

Because, the actual problem has not been resolved thats why I have not marked any answer.

Any alternate path to accomplish this task?

Thanks,

|||

Hi,

The code i have posted above worked just fine for me (registering the assembly as unsafe). My setup is Windows XP SP2, SQL Server 2005, Yahoo Messenger 7.5.0.819. I am using Windows authentication and my machine is on a domain. I am admin on the machine as well as on SQL Server. SQL Server is running under Local System.

Could you please post your complete code that throws this exception. Also provide details on your setup. It looks like the account you are running under does not have sufficient privileges to open the process. If you search on the internet you would find posts like http://www.thescripts.com/forum/thread162942.html that provide some explanation and suggestions.

Thanks,

-Vineet.

|||

Hi Vineet,

I have just changed the login on account for sqlservice.exe from domain to local system.. now even I am loged on to pc with a domain login.. I am able to impersonate the user.. It is working fine ..

The actual problem was in impersonation...

the Sqlserver was running under network service acount while I was loged using domain user login..

secondly, at start I was using external_access while now with Unsafe..

At the end .. I am able to kill a process, start a process from stored procedure..(SQLCLR SP)

I am closing this thread now..

Thank you all friends for replies.

How to use cell data security with visual totals?

Hi,

We are working on a project with SQL Server 2005 and SSAS.

We created several roles using dimension security and one special role that requires cell data access permissions (i.e. cell security).

This last role is giving us trouble since we do not know how to implement visual totals on cell security.

A problem description follows:

1) We have a budget and expenses cube with a) Account, b) Time and c) Cost Center dimensions
2) The special role was created for a group of users who have the following requirement for data access permission:
- for some cost centers, restrict access to some accounts
- and for the rest of cost centers see all accounts
3) When looking at data at the cost center and account level, the role works fine. Restrictions are applied correctly.
4) However when looking at the data at the cost center level ONLY, the aggregated total shows a sum for all accounts, regardless of restrictions.


We know that if you use regular dimension security, you can enable Visual Totals in order to have aggregated values that reflect
the restrictions applied at the atomic level.

However, we do not know how to apply visual totals on cell data security. If anyone has faced similar situation,
we would appreciate any help on how to do this.


Another way to put it:

1) In a cube with a Product dimension (Family > Category > Product) and a Geography dimension (Country > State > City)
2) You can set dimension security to restrict access to certain products.
3) If you enable Visual Totals when creating the role, the aggregations at the Category level will show total values excluding amounts for those restricted products.
4) If you do not enable Visual Totals, the aggregated totals at the Category level will add up all products, regardless of access restrictions at the product level.

We are trying to achieve the same with Cell Data Access Permissions, but there is no option to Enable Visual Totals. For instance:

1) Same cube as above
3) Your create a role with cell data access permission; for some cities, you restrict acess to some products, and for all other cities allow access to all products.
4) When you look at data at the City level, you want to aggregate totals not for all products, but excluding amounts for those restricted ones.


We would appreciate your help on this enormously!

Cheers!
jbadillo@.streamnova.com

Cell security was not designed to support visual totals as you described.|||

Hi,

Is there a way around this? Instead of using visual totals, is there some other way to get the right totals?

Cheers

|||

One approach, which seems to work in limited testing with Adventure Works, would involve introducing cell security MDX conditions into the cube MDX script. Basically, a scoped calculation sets the secured cell values to NULL, which will cause the aggregation of those values up the hierarchy to adjust accordingly. However, when cube cells are browsed, the secured cells will still show "#N/A". The limitation with this approach, of course, is that user and/or role logic will be needed, so that unrestricted users are unaffected.

The simplified scenario in Adventure Works was as follows:

For user XYZ, secure the data for Bikes in CY 2003, and rollups in the Sales Summary measure group should reflect this.

The Cell Read Permission expression (for a role with user XYZ as member) is:

Not ([Date].[Calendar].CurrentMember is [Date].[Calendar].[CY 2003]
and [Product].[Product Categories].CurrentMember is [Product].[Product Categories].[Bikes])

And the cube calculation MDX script is something like:

Scope(MeasureGroupMeasures("Sales Summary"),

[Date].[Calendar Year].&[2003],

[Product].[Category].[All Products].[Bikes]);

IF UserName = "XYZ"

THEN this = NULL END IF;

End Scope;

How to use CDO to send mail with attachment

I have a stored proc thats basically a copy of the script from MS to create
sp_send_cdosysmail.
This work fine using our mailrelay, but there seems to be no clear way to
add an attachment.
I've tried a simple:
EXEC @.hr = sp_OAMethod @.iMsg, 'AttachFile', NULL, @.Attachment
but that just causes an unknown name error.
I've also tried creating an attachment object but I can't seems to assciate
it with the original cdo.message:
EXEC @.hr = sp_OASetProperty @.iMsg, 'MailFormat', @.Body
EXEC @.hr = sp_OACreate 'CDO.Attachment', @.iATT OUT
EXEC @.hr = sp_OASetProperty @.iATT, 'Position', 0
EXEC @.hr = sp_OASetProperty @.iATT, 'Type', @.CdoFileData
EXEC @.hr = sp_OASetProperty @.iATT, 'Name', @.Attachment
EXEC @.hr = sp_OAMethod @.iMsg, 'CDO.Message.Attachment.Update', null,@.iATT
I've tried variations on creation of the original object and methods, but I
basically just guessing!
I've read somewhere that the file has to be accessable as a http path. This
is purely a SQL 2000 server, no extras like IIS or any form of exchange
client.
Has anyone sent attachments using SQL server and CDO? Can you please offer
some assisance.
Thanks in advance.Typically, I've found out what I need to know about 30mins after this post.
Why doesn't it happen 30 minutes after you first start looking!
Ha|||Hi, Phil
Would you mind sharing your idea about 'CDO sending mail with attachment'?
1. What is the syntax of CDO with attachment?
2. How to use the result of query as attachment?
Thanks a lot!
Tianya
"Phil_Edney" wrote:

> I have a stored proc thats basically a copy of the script from MS to creat
e
> sp_send_cdosysmail.
> This work fine using our mailrelay, but there seems to be no clear way to
> add an attachment.
> I've tried a simple:
> EXEC @.hr = sp_OAMethod @.iMsg, 'AttachFile', NULL, @.Attachment
> but that just causes an unknown name error.
> I've also tried creating an attachment object but I can't seems to assciat
e
> it with the original cdo.message:
> EXEC @.hr = sp_OASetProperty @.iMsg, 'MailFormat', @.Body
> EXEC @.hr = sp_OACreate 'CDO.Attachment', @.iATT OUT
> EXEC @.hr = sp_OASetProperty @.iATT, 'Position', 0
> EXEC @.hr = sp_OASetProperty @.iATT, 'Type', @.CdoFileData
> EXEC @.hr = sp_OASetProperty @.iATT, 'Name', @.Attachment
> EXEC @.hr = sp_OAMethod @.iMsg, 'CDO.Message.Attachment.Update', null,@.iA
TT
> I've tried variations on creation of the original object and methods, but
I
> basically just guessing!
> I've read somewhere that the file has to be accessable as a http path. Thi
s
> is purely a SQL 2000 server, no extras like IIS or any form of exchange
> client.
> Has anyone sent attachments using SQL server and CDO? Can you please offer
> some assisance.
> Thanks in advance.|||I found a solution at the following web site.
http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=20649
"Tianya" wrote:
> Hi, Phil
> Would you mind sharing your idea about 'CDO sending mail with attachment'?
> 1. What is the syntax of CDO with attachment?
> 2. How to use the result of query as attachment?
> Thanks a lot!
> Tianya
>
> "Phil_Edney" wrote:
>

How to use CASE WHEN statement in Function

Hi,
My Function as follow-->
CREATE FUNCTION fnXX04 ( @.cemk CHAR(1))
RETURNS CHAR(9)
AS
BEGIN
IF @.cemk = '1'
BEGIN
RETURN 'XX0400100'
END
RETURN 'XX0400200'
END
My Case When statement like this-->
CASE
WHEN iv_cemk = 0 THEN 'XX0400200'
ELSE 'XX0400100'
END AS iv_cemk
And could I replace IF @.cmk='1' BEGIN... to CASE WHEN statement in
Function?
How should I do?
Thanks!
AngiHi Angi,
what about
CREATE FUNCTION fnXX04 ( @.cemk CHAR(1))
RETURNS CHAR(9)
AS
BEGIN
declare @.cReturn char(9)
set @.cReturn = (case @.cemk
when '1' then 'XX0400100'
else 'XX0400200'
end)
return @.cReturn
END
HTH
Meinhard
"angi" <angi@.microsoft.public.sqlserver.olap> schrieb im Newsbeitrag
news:OJrAXO4pEHA.2864@.TK2MSFTNGP12.phx.gbl...
> Hi,
> My Function as follow-->
> CREATE FUNCTION fnXX04 ( @.cemk CHAR(1))
> RETURNS CHAR(9)
> AS
> BEGIN
> IF @.cemk = '1'
> BEGIN
> RETURN 'XX0400100'
> END
> RETURN 'XX0400200'
> END
> My Case When statement like this-->
> CASE
> WHEN iv_cemk = 0 THEN 'XX0400200'
> ELSE 'XX0400100'
> END AS iv_cemk
> And could I replace IF @.cmk='1' BEGIN... to CASE WHEN statement in
> Function?
> How should I do?
> Thanks!
> Angi
>|||Hi, Meinhard
Thank you very much!
And there is aother way like follow..
BEGIN
RETURN CASE WHEN @.cemk='1' THEN 'XX0400100'
ELSE 'XX0400200'
END
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
And I have another question there, syntax like follow..
CREATE FUNCTION fnXY13 (@.iden CHAR(4), @.csct CHAR(2), @.cect CHAR(2))
RETURNS CHAR(9)
AS
BEGIN
RETURN
CASE--XY13AA
WHEN @.iden = '7660' AND @.iden LIKE '00%%' THEN
CASE
WHEN @.csct = 'f1' THEN 'XY1300100'
WHEN @.csct = 'f2' THEN 'XY1300200'
ELSE 'XY1300500'
END
ELSE 'X99999999'
END
CASE--XY13BB
WHEN @.iden = '7660' AND @.iden LIKE '00%%' THEN
CASE
WHEN @.cect = 'f1' THEN 'XY1300100'
WHEN @.cect = 'f2' THEN 'XY1300200'
ELSE 'XY1300500'
END
ELSE 'X99999999'
END
CASE--XY13CC
WHEN @.iden IN ('0406','0408','0409','0419','0501') THEN
CASE
WHEN @.cect = 'f1' THEN 'XY1300100'
WHEN @.cect = 'f2' THEN 'XY1300200'
ELSE 'XY1300500'
END
ELSE 'X99999999'
END
END
There are 3 different CASE WHEN conditions and how could I combine it in a
Function?
Thanks!
Angi
"Meinhard Schnoor-Matriciani" <codehack@.freenet.de> ¼¶¼g©ó¶l¥ó·s»D
:2s4ev1F1h4vb5U1@.uni-berlin.de...
> Hi Angi,
> what about
>
> CREATE FUNCTION fnXX04 ( @.cemk CHAR(1))
> RETURNS CHAR(9)
> AS
> BEGIN
> declare @.cReturn char(9)
> set @.cReturn = (case @.cemk
> when '1' then 'XX0400100'
> else 'XX0400200'
> end)
> return @.cReturn
> END
> HTH
> Meinhard
> "angi" <angi@.microsoft.public.sqlserver.olap> schrieb im Newsbeitrag
> news:OJrAXO4pEHA.2864@.TK2MSFTNGP12.phx.gbl...
> > Hi,
> >
> > My Function as follow-->
> >
> > CREATE FUNCTION fnXX04 ( @.cemk CHAR(1))
> > RETURNS CHAR(9)
> > AS
> > BEGIN
> > IF @.cemk = '1'
> > BEGIN
> > RETURN 'XX0400100'
> > END
> > RETURN 'XX0400200'
> > END
> >
> > My Case When statement like this-->
> >
> > CASE
> > WHEN iv_cemk = 0 THEN 'XX0400200'
> > ELSE 'XX0400100'
> > END AS iv_cemk
> >
> > And could I replace IF @.cmk='1' BEGIN... to CASE WHEN statement in
> > Function?
> > How should I do?
> >
> > Thanks!
> > Angi
> >
> >
>

How to use CASE WHEN statement in Function

Hi,
My Function as follow-->
CREATE FUNCTION fnXX04 ( @.cemk CHAR(1))
RETURNS CHAR(9)
AS
BEGIN
IF @.cemk = '1'
BEGIN
RETURN 'XX0400100'
END
RETURN 'XX0400200'
END
My Case When statement like this-->
CASE
WHEN iv_cemk = 0 THEN 'XX0400200'
ELSE 'XX0400100'
END AS iv_cemk
And could I replace IF @.cmk='1' BEGIN... to CASE WHEN statement in
Function?
How should I do?
Thanks!
Angi
Hi Angi,
what about
CREATE FUNCTION fnXX04 ( @.cemk CHAR(1))
RETURNS CHAR(9)
AS
BEGIN
declare @.cReturn char(9)
set @.cReturn = (case @.cemk
when '1' then 'XX0400100'
else 'XX0400200'
end)
return @.cReturn
END
HTH
Meinhard
"angi" <angi@.microsoft.public.sqlserver.olap> schrieb im Newsbeitrag
news:OJrAXO4pEHA.2864@.TK2MSFTNGP12.phx.gbl...
> Hi,
> My Function as follow-->
> CREATE FUNCTION fnXX04 ( @.cemk CHAR(1))
> RETURNS CHAR(9)
> AS
> BEGIN
> IF @.cemk = '1'
> BEGIN
> RETURN 'XX0400100'
> END
> RETURN 'XX0400200'
> END
> My Case When statement like this-->
> CASE
> WHEN iv_cemk = 0 THEN 'XX0400200'
> ELSE 'XX0400100'
> END AS iv_cemk
> And could I replace IF @.cmk='1' BEGIN... to CASE WHEN statement in
> Function?
> How should I do?
> Thanks!
> Angi
>
|||Hi, Meinhard
Thank you very much!
And there is aother way like follow..
BEGIN
RETURN CASE WHEN @.cemk='1' THEN 'XX0400100'
ELSE 'XX0400200'
END
END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~
And I have another question there, syntax like follow..
CREATE FUNCTION fnXY13 (@.iden CHAR(4), @.csct CHAR(2), @.cect CHAR(2))
RETURNS CHAR(9)
AS
BEGIN
RETURN
CASE--XY13AA
WHEN @.iden = '7660' AND @.iden LIKE '00%%' THEN
CASE
WHEN @.csct = 'f1' THEN 'XY1300100'
WHEN @.csct = 'f2' THEN 'XY1300200'
ELSE 'XY1300500'
END
ELSE 'X99999999'
END
CASE--XY13BB
WHEN @.iden = '7660' AND @.iden LIKE '00%%' THEN
CASE
WHEN @.cect = 'f1' THEN 'XY1300100'
WHEN @.cect = 'f2' THEN 'XY1300200'
ELSE 'XY1300500'
END
ELSE 'X99999999'
END
CASE--XY13CC
WHEN @.iden IN ('0406','0408','0409','0419','0501') THEN
CASE
WHEN @.cect = 'f1' THEN 'XY1300100'
WHEN @.cect = 'f2' THEN 'XY1300200'
ELSE 'XY1300500'
END
ELSE 'X99999999'
END
END
There are 3 different CASE WHEN conditions and how could I combine it in a
Function?
Thanks!
Angi
"Meinhard Schnoor-Matriciani" <codehack@.freenet.de> glsD
:2s4ev1F1h4vb5U1@.uni-berlin.de...
> Hi Angi,
> what about
>
> CREATE FUNCTION fnXX04 ( @.cemk CHAR(1))
> RETURNS CHAR(9)
> AS
> BEGIN
> declare @.cReturn char(9)
> set @.cReturn = (case @.cemk
> when '1' then 'XX0400100'
> else 'XX0400200'
> end)
> return @.cReturn
> END
> HTH
> Meinhard
> "angi" <angi@.microsoft.public.sqlserver.olap> schrieb im Newsbeitrag
> news:OJrAXO4pEHA.2864@.TK2MSFTNGP12.phx.gbl...
>
|||Same as the answer in the previous post. Just assign to variables in your
logic, then RETURN the variable at the end.
Get the CASE statements working stand-alone in QA first.
Jeff
"angi" <angi@.microsoft.public.sqlserver.olap> wrote in message
news:eqMxG95pEHA.2484@.TK2MSFTNGP09.phx.gbl...
> Hi, Meinhard
> Thank you very much!
> And there is aother way like follow..
> BEGIN
> RETURN CASE WHEN @.cemk='1' THEN 'XX0400100'
> ELSE 'XX0400200'
> END
> END
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~
> And I have another question there, syntax like follow..
> CREATE FUNCTION fnXY13 (@.iden CHAR(4), @.csct CHAR(2), @.cect CHAR(2))
> RETURNS CHAR(9)
> AS
> BEGIN
> RETURN
> CASE--XY13AA
> WHEN @.iden = '7660' AND @.iden LIKE '00%%' THEN
> CASE
> WHEN @.csct = 'f1' THEN 'XY1300100'
> WHEN @.csct = 'f2' THEN 'XY1300200'
> ELSE 'XY1300500'
> END
> ELSE 'X99999999'
> END
> CASE--XY13BB
> WHEN @.iden = '7660' AND @.iden LIKE '00%%' THEN
> CASE
> WHEN @.cect = 'f1' THEN 'XY1300100'
> WHEN @.cect = 'f2' THEN 'XY1300200'
> ELSE 'XY1300500'
> END
> ELSE 'X99999999'
> END
> CASE--XY13CC
> WHEN @.iden IN ('0406','0408','0409','0419','0501') THEN
> CASE
> WHEN @.cect = 'f1' THEN 'XY1300100'
> WHEN @.cect = 'f2' THEN 'XY1300200'
> ELSE 'XY1300500'
> END
> ELSE 'X99999999'
> END
> END
> There are 3 different CASE WHEN conditions and how could I combine it in a
> Function?
> Thanks!
> Angi
>
> "Meinhard Schnoor-Matriciani" <codehack@.freenet.de> glsD
> :2s4ev1F1h4vb5U1@.uni-berlin.de...
>

How to use Case Statement

I tried and came up with no solution.
I need to use Stored procedure and no dynamic sql.
I ma using ms sql 2000 service pack 3
I am using three different tables. How I can make it to run union statements
only for those table where passing values for the variable is 1
Thanks
Tanweer
Declare @.people_list int
Declare @.client_list int
Declare @.joborder_list int
set @.people_list=1
set @.client_list =0
set @.joborder_list =1
select id, code form people_list
union
select id, code form Client_list
union
select id, code form joborder_listselect id, code form people_list
WHERE @.people_list = 1
union
select id, code form Client_list
WHERE @.client_list = 1
union
select id, code form joborder_list
WHERE @.joborder_list = 1
Roy Harvey
Beacon Falls, CT
On Fri, 16 Jun 2006 16:22:01 -0700, Tanweer
<Tanweer@.discussions.microsoft.com> wrote:

>I tried and came up with no solution.
>I need to use Stored procedure and no dynamic sql.
>I ma using ms sql 2000 service pack 3
>I am using three different tables. How I can make it to run union statement
s
>only for those table where passing values for the variable is 1
>Thanks
>Tanweer
>
>Declare @.people_list int
>Declare @.client_list int
>Declare @.joborder_list int
>set @.people_list=1
>set @.client_list =0
>set @.joborder_list =1
>select id, code form people_list
>union
>select id, code form Client_list
>union
>select id, code form joborder_list
>
>
>|||Try:
SELECT id, code form people_list
WHERE @.people_list = 1
UNION
SELECT id, code form Client_list
WHERE @.client_list = 1
UNION
SELECT id, code form joborder_list
WHERE @.joborder_list =1
Also, consider using UNION ALL instead of UNION unless you need to remove
duplicate rows in the result.
Hope this helps.
Dan Guzman
SQL Server MVP
"Tanweer" <Tanweer@.discussions.microsoft.com> wrote in message
news:86921632-36FA-4AD8-857D-4A639725B574@.microsoft.com...
>I tried and came up with no solution.
> I need to use Stored procedure and no dynamic sql.
> I ma using ms sql 2000 service pack 3
> I am using three different tables. How I can make it to run union
> statements
> only for those table where passing values for the variable is 1
> Thanks
> Tanweer
>
> Declare @.people_list int
> Declare @.client_list int
> Declare @.joborder_list int
> set @.people_list=1
> set @.client_list =0
> set @.joborder_list =1
> select id, code form people_list
> union
> select id, code form Client_list
> union
> select id, code form joborder_list
>
>
>|||First of all, CASE is an expression, not a statement, so it has to be used
as a value inside a statement. There is probably some way to get a CASE
expression to help you hear, but you might try something like this instead:
Declare @.people_list int
Declare @.client_list int
Declare @.joborder_list int
set @.people_list=1
set @.client_list =0
set @.joborder_list =1
select id, code form people_list
where @.people_list=1
union
select id, code form Client_list
where @.client_list = 1
union
select id, code form joborder_list
where @.joborder_list =1
So the where clauses will resolve to either WHERE 1=1, which will return all
the rows, or WHERE 0 =1 which will return none of the rows.
HTH
Kalen Delaney, SQL Server MVP
"Tanweer" <Tanweer@.discussions.microsoft.com> wrote in message
news:86921632-36FA-4AD8-857D-4A639725B574@.microsoft.com...
>I tried and came up with no solution.
> I need to use Stored procedure and no dynamic sql.
> I ma using ms sql 2000 service pack 3
> I am using three different tables. How I can make it to run union
> statements
> only for those table where passing values for the variable is 1
> Thanks
> Tanweer
>
> Declare @.people_list int
> Declare @.client_list int
> Declare @.joborder_list int
> set @.people_list=1
> set @.client_list =0
> set @.joborder_list =1
> select id, code form people_list
> union
> select id, code form Client_list
> union
> select id, code form joborder_list
>
>
>|||Love you guys
Great help
Thanks very much
Tanweer
"Kalen Delaney" wrote:

> First of all, CASE is an expression, not a statement, so it has to be used
> as a value inside a statement. There is probably some way to get a CASE
> expression to help you hear, but you might try something like this instead
:
>
> Declare @.people_list int
> Declare @.client_list int
> Declare @.joborder_list int
> set @.people_list=1
> set @.client_list =0
> set @.joborder_list =1
> select id, code form people_list
> where @.people_list=1
> union
> select id, code form Client_list
> where @.client_list = 1
> union
> select id, code form joborder_list
> where @.joborder_list =1
> So the where clauses will resolve to either WHERE 1=1, which will return a
ll
> the rows, or WHERE 0 =1 which will return none of the rows.
> --
> HTH
> Kalen Delaney, SQL Server MVP
>
> "Tanweer" <Tanweer@.discussions.microsoft.com> wrote in message
> news:86921632-36FA-4AD8-857D-4A639725B574@.microsoft.com...
>
>

How to use Case or If statement in Inner Join ?


Hi All,

I am in need for to write the following query for a stored procedure in SQL Server 2000. Please observe the T-SQL code first.
Please disregard the numbers and Product Numbers, they are not the correct data. I used them for ease of understanding. But the query is identical.

Code Block

SELECT
C.iOwnerid,
MAX (C.DtInsertDate) AS [dtLastIssueDate]
INTO #Tble
FROM CustomerProduct C
CASE WHEN @.vchSubscription = 'Weekly' THEN
INNER JOIN ProductMaster PM ON PM.chProductNumber = C.chProductNumber
AND ( ( PM.vchUser7='101557' AND PM.vchUser8='101557' ) -- Category and SubCategory
OR PM.chProductNumber IN (
'weekly1', 'Weekly2', 'Weekly3', 'Weekly4' )
)
AND C.dtInsertDate > = @.dtIssueDate

CASE WHEN @.vchSubscription = 'Monthly' THEN

INNER JOIN ProductMaster PM ON PM.chProductNumber = C.chProductNumber
AND ( ( PM.vchUser7='101557' AND PM.vchUser8='101557' )
OR PM.chProductNumber IN (
'Jan', 'Feb', 'Mar', ....'Dec')
)
AND C.dtInsertDate > = @.dtIssueDate

END

GROUP BY C.iOwnerid, PM.vchUser7, PM.vchUser8


my requirement is join the same table, but depending on the subscription type i have to join to different product numbers.
I hope you understand. I have been trying this since yesterday, but no luck.

Any help would be greatly appreciated.Maybe this:

SELECT
C.iOwnerid,
MAX (C.DtInsertDate) AS [dtLastIssueDate]
INTO #Tble
FROM CustomerProduct C
INNER JOIN ProductMaster PM
ON PM.chProductNumber = C.chProductNumber
AND ( ( PM.vchUser7='101557' AND PM.vchUser8='101557' ) -- Category and SubCategory
OR
( @.vchSubscription = 'Weekly' AND PM.chProductNumber IN (
'weekly1', 'Weekly2', 'Weekly3', 'Weekly4' )
)
OR
( @.vchSubscription = 'Monthly' AND PM.chProductNumber IN (
'Jan', 'Feb', 'Mar', ....'Dec')
)
)
AND C.dtInsertDate > = @.dtIssueDate
GROUP BY C.iOwnerid, PM.vchUser7, PM.vchUser8|||

MadhuBabu,

You can use different statements or dynamic sql. You can not use "case" to control program flow. It is a function, so it has to return something when used.

if @.vchSubscription = 'Weekly'

select ...

else

if @.vchSubscription = 'Monthly'

select ...

The Curse and Blessings of Dynamic SQL

http://www.sommarskog.se/dynamic_sql.html

AMB|||

Hi Dale J Smile

Thank you very much for the answer. Well, just before 30 minutes I figured another less impressive method which is agreed on. following is the code for that

Code Block

DECLARE @.dtIssueDate DATETIME
SET @.dtIssueDate = '2007-10-01'

SELECT
C.iOwnerid,
MAX (C.DtInsertDate) AS [dtLastIssueDate]
INTO #Tble
FROM CustomerProduct C
INNER JOIN ProductMaster PM ON PM.chProductNumber = C.chProductNumber
AND ( ( PM.vchUser7='101557' AND PM.vchUser8='101557' )
OR PM.chProductNumber IN (
'week1', 'week2', .. 'week4' ,
'Jan', 'Feb', ... , 'Dec'
)
)
AND PM.tiRecordStatus = 1
AND C.dtInsertDate > = @.dtIssueDate
GROUP BY C.iOwnerid, PM.vchUser7, PM.vchUser8

/*
Remove Weekly Subscribers
*/
IF @.vchJournal = 'Monthly'
BEGIN
DELETE FROM #Tble WHERE iOwnerId IN (
SELECT DISTINCT C.iOwnerId FROM CustomerProduct C
INNER JOIN ProductMaster PM ON pm.chProductNumber = C.chProductNumber
AND PM.chProductNumber IN ('week1', 'week2', .., 'week4')
AND PM.tiRecordStatus = 1
AND C.dtInsertDate > = @.dtIssueDate
)
END
ELSE IF @.vchJournal = 'Weekly' /* Remove Monthly Subscribers */
BEGIN
DELETE FROM #Tble WHERE iOwnerId IN (
SELECT DISTINCT C.iOwnerId FROM CustomerProduct C
INNER JOIN ProductMaster PM ON pm.chProductNumber = C.chProductNumber
AND PM.chProductNumber IN ('Jan', 'Feb', ... , 'Dec')
AND PM.tiRecordStatus = 1
AND C.dtInsertDate > = @.dtIssueDate
)
END


But for sure, your code is more optimal, and am implementing it now...
Many Many Thanks.

how to use CASE or IF in SSIS

All,

what's data flow task works with CASE to IF ?

CASE WHEN .ACTION = 'TER' THEN COL 1 ELSE COL 1 end

Thanks

The Derived Column transformation allows you to do this. This is the operator that you're interested in: http://msdn2.microsoft.com/en-us/library/ms141680.aspx

-Jamie

how to use cascade parameters with report model

Hi,

I know the use of cascading parameters when you use queries in your dataset.

But could somebody explain to me how to use them when using a reportmodel ?

Vinnie

Ok,

So after long research and testing and testing and test......

i have finaly found the solution.

In order to use cascading parameters with datasets based on models this is how you proceed.

Use the same filtersettings in your datasets that you want to limit to a previous dataset. (ok, i know this sounds like sh...)

but i will explain with an example.

supose you have in your dataset based on an entity with various fields like datetime, userid, username, ...

the goal is to make a report that will let me select a time period (from ... to ...) and will let me select one or more agents that

worked during that period.

This is how i do that :

Create a first dataset based on an entity (eg: UserData). Select the fields you want to show into the report.

Next specify the filters you want to apply to the report.

First we will define your start and end date :

drag your datetime field into the filter area (this will be your start date) and drag the same field back again in the filter area

(this will be your end date). click on the first filter (equals) and change it to 'on or after'. Do this also for the second filter and

change it into 'on or before'. Then click on both of the filters and click on 'prompt'. (this is to indicate to the program that it has

to prompt you to fill in the parameter. Click ok to confirm these filters and go to report parameters menu. Normaly there should

be two parameters created (DateTime and DateTime1 or something like that). Change the type to a datetime of both the

params. You can also change the label if needed.

So you run the report now, you will be first prompted to set a start and an end date.

Now to setup a third parameter (i want a list of the users who worked during that period i indicated with my start and end

date)

Open the first dataset, go to filters and drag and drop the userID (or wathever) entity into the filters. Make it again so it prompts

you for an input. Change "equals" into "in a list".(this is to be able to select more then one user)

Create a second dataset based on the same entity. Select UserId and UserName as fields you want to use in that dataset.

Go to filters and do the same action with the datetime field as you did in dataset1.

"

drag your datetime field into the filter area (this will be your start date) and drag the same field back again in the filter area

(this will be your end date). click on the first filter (equals) and change it to 'on or after'. Do this also for the second filter and

change it into 'on or before'. Then click on both of the filters and click on 'prompt'. (this is to indicate to the program that it has

to prompt you to fill in the parameter. Click ok to confirm these filters

"

Now go again to report parameters menu. A third parameter will be created (Userid). Select this parameter. It will be defined

as a string. check the multi value option. In the available values select from query. select "dataset2" (or whatever you named

it). select userid as value field and username as label field..

Now, when you run the report, and you input the start and end date, your user selection will be limited to your selected time

period (this can be seen because it will take a few moments to populate the user selection listbox).

I know this is a long explanation but i hope it is clear. After all the solution was simple, but i didn't find the answer.

Greetings

Vinnie

how to use cascade parameters with report model

Hi,

I know the use of cascading parameters when you use queries in your dataset.

But could somebody explain to me how to use them when using a reportmodel ?

Vinnie

Ok,

So after long research and testing and testing and test......

i have finaly found the solution.

In order to use cascading parameters with datasets based on models this is how you proceed.

Use the same filtersettings in your datasets that you want to limit to a previous dataset. (ok, i know this sounds like sh...)

but i will explain with an example.

supose you have in your dataset based on an entity with various fields like datetime, userid, username, ...

the goal is to make a report that will let me select a time period (from ... to ...) and will let me select one or more agents that

worked during that period.

This is how i do that :

Create a first dataset based on an entity (eg: UserData). Select the fields you want to show into the report.

Next specify the filters you want to apply to the report.

First we will define your start and end date :

drag your datetime field into the filter area (this will be your start date) and drag the same field back again in the filter area

(this will be your end date). click on the first filter (equals) and change it to 'on or after'. Do this also for the second filter and

change it into 'on or before'. Then click on both of the filters and click on 'prompt'. (this is to indicate to the program that it has

to prompt you to fill in the parameter. Click ok to confirm these filters and go to report parameters menu. Normaly there should

be two parameters created (DateTime and DateTime1 or something like that). Change the type to a datetime of both the

params. You can also change the label if needed.

So you run the report now, you will be first prompted to set a start and an end date.

Now to setup a third parameter (i want a list of the users who worked during that period i indicated with my start and end

date)

Open the first dataset, go to filters and drag and drop the userID (or wathever) entity into the filters. Make it again so it prompts

you for an input. Change "equals" into "in a list".(this is to be able to select more then one user)

Create a second dataset based on the same entity. Select UserId and UserName as fields you want to use in that dataset.

Go to filters and do the same action with the datetime field as you did in dataset1.

"

drag your datetime field into the filter area (this will be your start date) and drag the same field back again in the filter area

(this will be your end date). click on the first filter (equals) and change it to 'on or after'. Do this also for the second filter and

change it into 'on or before'. Then click on both of the filters and click on 'prompt'. (this is to indicate to the program that it has

to prompt you to fill in the parameter. Click ok to confirm these filters

"

Now go again to report parameters menu. A third parameter will be created (Userid). Select this parameter. It will be defined

as a string. check the multi value option. In the available values select from query. select "dataset2" (or whatever you named

it). select userid as value field and username as label field..

Now, when you run the report, and you input the start and end date, your user selection will be limited to your selected time

period (this can be seen because it will take a few moments to populate the user selection listbox).

I know this is a long explanation but i hope it is clear. After all the solution was simple, but i didn't find the answer.

Greetings

Vinnie

How to use cartesian join to get multiple records

Hello !
How to use correctly catesian join to get follwing result
Source table
Col1, Col2, KOKKU
1 1 4
1 2 2
1 3 1
And result must be (the column KOKKU defines how much every row must by
multiplied)
Col1, Col2
1 1
1 1
1 1
1 1
1 2
1 2
1 3
There must be come cartesian(CROSS) join solution
Kuido
Message posted via http://www.webservertalk.comI would use a Numbers table for this:
SELECT col1, col2
FROM YourTable AS T
INNER JOIN Numbers AS N
ON N.num BETWEEN 1 AND T.kokku
(BTW an INNER JOIN is a subset of a Cartesian Product)
There are plenty of ways to build a numbers table, but since you only ever
have to do it once the method isn't very important. I actually prefer to use
a loop:
CREATE TABLE Numbers
(num INTEGER PRIMARY KEY)
INSERT INTO Numbers VALUES (1)
WHILE (SELECT MAX(num) FROM Numbers)<65536
INSERT INTO Numbers (num)
SELECT num+(SELECT MAX(num) FROM Numbers)
FROM Numbers
Some other suggestions here:
http://www.bizdatasolutions.com/tsql/tblnumbers.asp
David Portas
SQL Server MVP
--

how to use cairage return chr(13)

hi ,

i am unable to concatenate...
actually i want the id number to be in the same line

for ex: hi ur id no - 3456
i want to get in the above format..but i am getting it as

"hi ur id is-
3456"
pls help me out.. i should use this in the sqr report
so hoe should i use the carige return chr(13)

Quote:

Originally Posted by pkashyap

hi ,

i am unable to concatenate...
actually i want the id number to be in the same line

for ex: hi ur id no - 3456
i want to get in the above format..but i am getting it as

"hi ur id is-
3456"
pls help me out.. i should use this in the sqr report
so hoe should i use the carige return chr(13)


Hi. Would you please post the code that is causing this output. That would make things much easier.
Thanks

How to use C# syntax in report expressions

I want to use C# syntax in report expressions.
I use WinForms ReportViewer in local mode.
How to use C# instead of VB.NET syntax ?
I'm thinking about the following approaches:
1. Create pre-processor which converts expressions in RDL file from C# to
VB. NET
2. Replace all expressions with a method which takes C# expression as string
parameter, evaluates it and returns result.
Any idea how to implement this ?
Where to find any samples of C# expression evaluator or C# VB .NET
expression converter ?
Andrus.On Mar 27, 4:34 am, "Andrus" <kobrule...@.hot.ee> wrote:
> I want to use C# syntax in report expressions.
> I use WinForms ReportViewer in local mode.
> How to use C# instead of VB.NET syntax ?
> I'm thinking about the following approaches:
> 1. Create pre-processor which converts expressions in RDL file from C# to
> VB. NET
> 2. Replace all expressions with a method which takes C# expression as string
> parameter, evaluates it and returns result.
> Any idea how to implement this ?
> Where to find any samples of C# expression evaluator or C# VB .NET
> expression converter ?
> Andrus.
I, myself, come from a C# background and needed to learn some basic
VB.NET for expressions in order to use SSRS 2005. Aside from basic
syntax, the two are highly similar. It doesn't seem like the time to
become familiar w/the report expressions, etc in VB.NET would be as
much of a trade off when compared to a custom C# to VB.NET expression
converting application. That said, here's one I found:
http://www.tangiblesoftwaresolutions.com/Product_Details/Instant_VB/Instant_VB.htm
Also, several are mentioned here:
http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/b4787e2e70c0b9df/6ec64748dea02d40?lnk=st&q=C%23+to+vb.net+conversion&rnum=4#6ec64748dea02d40
Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant|||> It doesn't seem like the time to
> become familiar w/the report expressions, etc in VB.NET would be as
> much of a trade off when compared to a custom C# to VB.NET expression
> converting application.
I noticed that I must write code in <Code> tags in VB .NET also.
So using reporting services requires learning full VB .NET language, not
only expressions.
I have read everywhere that .NET allows to select between C# and VB .NET
When this is fixed so that C# language can be used in RDLC files ?
Andrus.|||> I noticed that I must write code in <Code> tags in VB .NET also.
>So using reporting services requires learning full VB .NET language, not
>only expressions.
Really not true, or at least certainly not a big deal, if you put your code
in custom DLLs instead of embedding it in the report. Which you would
probably want to do for non-trivial code anyway. So put your code in custom
DLLs in C#, and go as crazy as you want creating custom functions (in C#)
which you can call in your report for anything where the built-in VB
functions seem non-intuitive or not effective from your POV.
>L<
"Andrus" <kobruleht2@.hot.ee> wrote in message
news:OWlLZNHcHHA.2120@.TK2MSFTNGP03.phx.gbl...
>> It doesn't seem like the time to
>> become familiar w/the report expressions, etc in VB.NET would be as
>> much of a trade off when compared to a custom C# to VB.NET expression
>> converting application.
> I noticed that I must write code in <Code> tags in VB .NET also.
> So using reporting services requires learning full VB .NET language, not
> only expressions.
> I have read everywhere that .NET allows to select between C# and VB .NET
> When this is fixed so that C# language can be used in RDLC files ?
> Andrus.

How to use C# DLL in Extended Stored Procedure?

Hello,

i have created one C# DLL

xp_hello.dll

Its having below code in Class1.cs

namespace xp_hello

{

public class Class1

{

public string xp_hello()

{

string strReturn = string.Empty;

strReturn = "Chirag Patel";

return strReturn;

}

}

}

i compiled that DLL and kept it in C drive.

now i am trying to create Extended stored procedure using

sp_addextendedproc 'xp_hello', 'c:\xp_hello.dll'

its showing successful creation.

Now i am trying to Execute it with

DECLARE @.txt varchar(33)

EXEC xp_hello @.txt OUTPUT

now its showing below message.

Msg 17751, Level 16, State 0, Procedure xp_hello, Line 1

Could not find the function xp_hello in the library xp_hello.dll. Reason: 127(The specified procedure could not be found.).

can anyone please help me out in this?

Thanks

Extended stored procedures are C++ coded. If you want to use the CLR you will have to use the SQL CLR project / the CLR integration in SQL Server. (which is available in SQL Server 2005)

Jens K. Suessmeyer

http://www.sqlserver2005.de

|||

Hello Jens,

Thanks a lot.

its done. i able to call C# DLL from Stored Proc.

Great,

Thanks.

How to Use Business Logic DLL

In my company, we have an extensive Business Logic Layer class library that
is used for several development projects. This works great for re-use and
streamlining project development. We would also like to extend this
capability to reporting services activities within the corporation. How can
we define a report in reporting services to use our class library vs an SQL
Datasource?I think your best bet would be to wrap some web services around your DLL and
then in RS 2005, you can create an XML data source. Connect to your web
services to pull in the data.
Otherwise, you would need to go into the Macro section of RS and add a
reference to your DLL, and then create functions to expose data elements. I
think that would less maintainable...
"Guy Thornton" wrote:
> In my company, we have an extensive Business Logic Layer class library that
> is used for several development projects. This works great for re-use and
> streamlining project development. We would also like to extend this
> capability to reporting services activities within the corporation. How can
> we define a report in reporting services to use our class library vs an SQL
> Datasource?

how to use bulk copy?

hi..

how to use bulk copy in MS SOL Server?

Please seehttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbcsql/od_6_040_101f.asp for more details information about bulk copy...

Lan

How to use both auto generated id and a guid in database

I downloaded the AdventureWorks OLTP Schema and am trying to use some of the design concepts that are used in this example but I don’t quite understand some things.

First there is a column named rowguid, at the moment I assume that this is a GUID. If this is wrong most likely my next question will make no sense.

Second if that is indeed a guid all the tables have another id; example would be Employee table would have employeeid and rowguid, why do this? My best guess is that you would use the guid to easily insert (linked/sync) data into multiple tables without needing to retrieve the id from the table that was first input into. My scenario would be inserting an employee; to insert an employee you need to create a row in the employee, contact and address tables and for ease you would use the guid to link these rows. But if this is the case wouldn’t there be sync issues that would arise?

If my guess is totally off please correct me also if anyone can direct me to some good resources that cover database design.

The schema can be downloaded at http://www.microsoft.com/downloads/details.aspx?familyid=0F6E0BCF-A1B5-4760-8D79-67970F93D5FF&displaylang=en#filelist

Thanks for any help.

The rowguid is actually used here as part of a replication example:

http://msdn2.microsoft.com/en-us/library/ms124807.aspx

Replication can add a column by this name to a schema to give it a unique value across servers. Rowguid is also a property that you can add to a guid column to tell it that it is an identifier for the row. You wouldn't generally want to have both types if you were designing a table yourself. You would just use the primary key that is set up to do the relationships and joins on.

They did this because they can use one datatype, always having a unique value across servers, no matter the table structures and type of the primary key.

how to use bookmarks in a report ??

I have a report with three different charts.
I would like to provide a link to each chart at the top of the report - so
when a user clicks the link, they are taken to the relevant chart.
Can anyone tell me how to create a bookmark on a chart (or a textbox, or
anything!) - and link to it.
I've looked at Microsofts "how-to" explanation - but it is vague, and gives
no example
TIAYou can create bookmarks by setting the "Document Map Label" on the
properties tab. You can set this on textbox columns, and doesnt look like you
can set this on charts. But the work around is -
Just above the chart, create a empty textbox. Right click on the textbox, go
to properties and on the visibility tab set the visibility to hidden.
(Because you dont want to see the textbox) Next on the Navigation tab on the
document map label enter "Chart1" also fill in a BookMark ID . Lets say
"Chart1BM". Now deploy the report and see. Since you created a document map
label, you will see a document map on the left side of the report, which will
take you directly to the chart1. Also if you want to jump to the chart1 from
somewhere in the report (and not from the document map). Right click (from
that point where you want a link to Chart1), go to properties and then select
navigation, and selecte jump to bookmark, and type in the bookmarkname name
that you gave before- "Chart1BM".
Hope that helps.
The document label is to create a table of contents type of thing, and the
BookMarkID is to set BookMarks
"grasshopper" wrote:
> I have a report with three different charts.
> I would like to provide a link to each chart at the top of the report - so
> when a user clicks the link, they are taken to the relevant chart.
> Can anyone tell me how to create a bookmark on a chart (or a textbox, or
> anything!) - and link to it.
> I've looked at Microsofts "how-to" explanation - but it is vague, and gives
> no example
> TIA|||Thanks for the info Nagini - I also found that this works:
select the item to be bookmarked. In the properties window (View |
Properties Window), there is a field called 'Bookmark'. Enter any unique
string in the bookmark property e.g. "bookmark1"
select the item that will serve as a link to the bookmark. Right-Click and
select 'Properties'. In the properties dialogue box - go to "Advanced >> |
Navigation tab| jump to bookmark". Enter the unique string "bookmark1" and
hit OK.
Preview the report and click on the link to jump to the bookmark.
The above will work for charts too, as they also have a 'bookmark' property
that can be used. I have used this method to drill-down from one chart to a
second more detailed chart via 'properties | navigation | bookmark'
Regards
"Nagini Indugula" wrote:
> You can create bookmarks by setting the "Document Map Label" on the
> properties tab. You can set this on textbox columns, and doesnt look like you
> can set this on charts. But the work around is -
> Just above the chart, create a empty textbox. Right click on the textbox, go
> to properties and on the visibility tab set the visibility to hidden.
> (Because you dont want to see the textbox) Next on the Navigation tab on the
> document map label enter "Chart1" also fill in a BookMark ID . Lets say
> "Chart1BM". Now deploy the report and see. Since you created a document map
> label, you will see a document map on the left side of the report, which will
> take you directly to the chart1. Also if you want to jump to the chart1 from
> somewhere in the report (and not from the document map). Right click (from
> that point where you want a link to Chart1), go to properties and then select
> navigation, and selecte jump to bookmark, and type in the bookmarkname name
> that you gave before- "Chart1BM".
> Hope that helps.
> The document label is to create a table of contents type of thing, and the
> BookMarkID is to set BookMarks
> "grasshopper" wrote:
> > I have a report with three different charts.
> >
> > I would like to provide a link to each chart at the top of the report - so
> > when a user clicks the link, they are taken to the relevant chart.
> >
> > Can anyone tell me how to create a bookmark on a chart (or a textbox, or
> > anything!) - and link to it.
> >
> > I've looked at Microsofts "how-to" explanation - but it is vague, and gives
> > no example
> >
> > TIA

How to use BETWEEN with custom-ordered values

We have a 10 digit primary key value in this format: M000123456. The
order for this key is first determined by positions 3 and 4 in this
example, then positions 1 and 2. So a brief sample of correct ordering
would look like this:
M000001501
M000011501
M000021501
M000001601
M000011601
M000021601

Now my question: how can I use a BETWEEN (or > and <) in my WHERE
clause to get a range of values for this column? I use the following
ORDER BY clause to control how the results are sorted, but I can't get
the same logic to work with BETWEEN in a WHERE clause.

ORDER BY SUBSTRING(<fieldname>, 7, 2), SUBSTRING (<fieldname>, 5, 2)
How do I return values between M000011501 and M000011601 for example?On 19 Dec 2004 16:36:14 -0800, ian.proffer@.gmail.com wrote:

>We have a 10 digit primary key value in this format: M000123456. The
>order for this key is first determined by positions 3 and 4 in this
>example, then positions 1 and 2. So a brief sample of correct ordering
>would look like this:
>M000001501
>M000011501
>M000021501
>M000001601
>M000011601
>M000021601
>Now my question: how can I use a BETWEEN (or > and <) in my WHERE
>clause to get a range of values for this column? I use the following
>ORDER BY clause to control how the results are sorted, but I can't get
>the same logic to work with BETWEEN in a WHERE clause.
>ORDER BY SUBSTRING(<fieldname>, 7, 2), SUBSTRING (<fieldname>, 5, 2)
>How do I return values between M000011501 and M000011601 for example?

Hi Ian,

Usually, this kind of requirement is a sign of a bad table design. I have
the suspicion that both the two digits in position 3 and 4 and the two
digits in position 1 and 2 have a specific meaning in your business. If
that is the case, you should probably store these as seperate columns. You
can always paste the different values together for outputting as one
column.

Anyway, based on your ORDER BY clause, the BETWEEN predicate would read

WHERE SUBSTRING(<columnname>, 7, 2) + SUBSTRING (<columnname>, 5, 2)
BETWEEN SUBSTRING('M000011501', 7, 2) + SUBSTRING ('M000011501', 5, 2)
AND SUBSTRING('M000011601', 7, 2) + SUBSTRING ('M000011601', 5, 2)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hi

It may be easier if you stored the correctly ordered string rather than the
one used for display, and have the display string in a view/computed column
or part of the select statement.

You don't say how the rest of the string is arranged, but something like:

SELECT SUBSTRING(<fieldname>, 7, 2) + SUBSTRING (<fieldname>, 5, 2) +
SUBSTRING (<fieldname>, 1, 4) + SUBSTRING (<fieldname>, 9, 2),
* FROM <tablename>
WHERE SUBSTRING(<fieldname>, 7, 2) + SUBSTRING (<fieldname>, 5, 2) +
SUBSTRING (<fieldname>, 1, 4) + SUBSTRING (<fieldname>, 9, 2) between
SUBSTRING('M000011501', 7, 2) + SUBSTRING ('M000011501', 5, 2) + SUBSTRING
('M000011501', 1, 4) + SUBSTRING ('M000011501', 9, 2)
and SUBSTRING('M000011601', 7, 2) + SUBSTRING ('M000011601', 5, 2) +
SUBSTRING ('M000011601', 1, 4) + SUBSTRING ('M000011601', 9, 2)
ORDER BY SUBSTRING(<fieldname>, 7, 2), SUBSTRING (<fieldname>, 5, 2)

will give your result.

John

<ian.proffer@.gmail.com> wrote in message
news:1103502974.453433.144600@.f14g2000cwb.googlegr oups.com...
> We have a 10 digit primary key value in this format: M000123456. The
> order for this key is first determined by positions 3 and 4 in this
> example, then positions 1 and 2. So a brief sample of correct ordering
> would look like this:
> M000001501
> M000011501
> M000021501
> M000001601
> M000011601
> M000021601
> Now my question: how can I use a BETWEEN (or > and <) in my WHERE
> clause to get a range of values for this column? I use the following
> ORDER BY clause to control how the results are sorted, but I can't get
> the same logic to work with BETWEEN in a WHERE clause.
> ORDER BY SUBSTRING(<fieldname>, 7, 2), SUBSTRING (<fieldname>, 5, 2)
> How do I return values between M000011501 and M000011601 for example?|||Thanks for the reply Hugo. (I don't usually multi-post, btw,
but...sorry.) Your solution works great, even though I didn't
accurately post my sample data (where M000251501 is followed by
M000001601).

And oh, if only I could redesign the table! Out of my control however
with this application <sigh>.

Thanks again,
-- Ian

how to use bcp utility..

sql2k on nt5.
i'd like to learn how to use bcp utility like bringing a Access mdb file
(just a table) into northwind database on sql server.
where should i run it and what the sytax should be like? (use trust
connection)
thank you.BCP is not the tool for bringing in a mdf. Take a look at DTS in
BooksOnLine for that.
--
Andrew J. Kelly SQL MVP
"== Steve Pdx==" <lins@.nospam.portptld.com> wrote in message
news:eR2K5K8MEHA.3636@.TK2MSFTNGP09.phx.gbl...
> sql2k on nt5.
> i'd like to learn how to use bcp utility like bringing a Access mdb file
> (just a table) into northwind database on sql server.
> where should i run it and what the sytax should be like? (use trust
> connection)
> thank you.
>|||BCP is just for importing text files. It is documented in Books on Line as
well.
Rand
This posting is provided "as is" with no warranties and confers no rights.

how to use bcp utility..

sql2k on nt5.
i'd like to learn how to use bcp utility like bringing a Access mdb file
(just a table) into northwind database on sql server.
where should i run it and what the sytax should be like? (use trust
connection)
thank you.
BCP is not the tool for bringing in a mdf. Take a look at DTS in
BooksOnLine for that.
Andrew J. Kelly SQL MVP
"== Steve Pdx==" <lins@.nospam.portptld.com> wrote in message
news:eR2K5K8MEHA.3636@.TK2MSFTNGP09.phx.gbl...
> sql2k on nt5.
> i'd like to learn how to use bcp utility like bringing a Access mdb file
> (just a table) into northwind database on sql server.
> where should i run it and what the sytax should be like? (use trust
> connection)
> thank you.
>
|||BCP is just for importing text files. It is documented in Books on Line as
well.
Rand
This posting is provided "as is" with no warranties and confers no rights.

how to use bcp utility..

sql2k on nt5.
i'd like to learn how to use bcp utility like bringing a Access mdb file
(just a table) into northwind database on sql server.
where should i run it and what the sytax should be like? (use trust
connection)
thank you.BCP is not the tool for bringing in a mdf. Take a look at DTS in
BooksOnLine for that.
Andrew J. Kelly SQL MVP
"== Steve Pdx==" <lins@.nospam.portptld.com> wrote in message
news:eR2K5K8MEHA.3636@.TK2MSFTNGP09.phx.gbl...
> sql2k on nt5.
> i'd like to learn how to use bcp utility like bringing a Access mdb file
> (just a table) into northwind database on sql server.
> where should i run it and what the sytax should be like? (use trust
> connection)
> thank you.
>|||BCP is just for importing text files. It is documented in Books on Line as
well.
Rand
This posting is provided "as is" with no warranties and confers no rights.

How to use bcp in at SQL Query analyzer

Dear All,
I need to do bcp in. The command I use at SQL Query
analyzer is
exec bcp 'schedule.dbo.emp_new'
out 'e:\sqlserver_bcp_data\new.out' -SSQLSERVER_TRY1 -Usa -
Ptrytry -c
But I am getting the error message
Server: Msg 179, Level 15, State 1, Line 1
Cannot use the OUTPUT option when passing a constant to a
stored procedure.
So, how to do bcp in. Please help me.
BCP is a command line utility, not a T-SQL command. So, try that command
from the command prompt.
You could also invoked such executables from Query Analyzer, using the
xp_cmdshell extended system stored procedure. See SQL Server Books Online
for more information.
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
"Sonia" <anonymous@.discussions.microsoft.com> wrote in message
news:2df0e01c46a5b$46289750$a301280a@.phx.gbl...
Dear All,
I need to do bcp in. The command I use at SQL Query
analyzer is
exec bcp 'schedule.dbo.emp_new'
out 'e:\sqlserver_bcp_data\new.out' -SSQLSERVER_TRY1 -Usa -
Ptrytry -c
But I am getting the error message
Server: Msg 179, Level 15, State 1, Line 1
Cannot use the OUTPUT option when passing a constant to a
stored procedure.
So, how to do bcp in. Please help me.
|||Hi,
You have to xp_cmdshell to execute a bcp from query analyzer.
master..xp_cmdshell 'bcp schedule.dbo.emp_new out
e:\sqlserver_bcp_data\new.out -SSQLSERVER_TRY1 -Usa -Ptrytry -c
Thanks
Hari
MCDBA
"Sonia" <anonymous@.discussions.microsoft.com> wrote in message
news:2df0e01c46a5b$46289750$a301280a@.phx.gbl...
> Dear All,
> I need to do bcp in. The command I use at SQL Query
> analyzer is
> exec bcp 'schedule.dbo.emp_new'
> out 'e:\sqlserver_bcp_data\new.out' -SSQLSERVER_TRY1 -Usa -
> Ptrytry -c
> But I am getting the error message
> Server: Msg 179, Level 15, State 1, Line 1
> Cannot use the OUTPUT option when passing a constant to a
> stored procedure.
> So, how to do bcp in. Please help me.
>
|||Sonia,
bcp is a commandline tool. To use it in QA you need to shell out and run
it using xp_cmdshell. Alternatively use BULK INSERT or DTS - the command
you posted actually bcps out, not in, so you need to change that.
example using xp_cmdshell:
exec master..xp_cmdshell 'bcp schedule.dbo.emp_new out
e:\sqlserver_bcp_data\new.out -SSQLSERVER_TRY1 -Usa -
Ptrytry -c'
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Sonia wrote:
> Dear All,
> I need to do bcp in. The command I use at SQL Query
> analyzer is
> exec bcp 'schedule.dbo.emp_new'
> out 'e:\sqlserver_bcp_data\new.out' -SSQLSERVER_TRY1 -Usa -
> Ptrytry -c
> But I am getting the error message
> Server: Msg 179, Level 15, State 1, Line 1
> Cannot use the OUTPUT option when passing a constant to a
> stored procedure.
> So, how to do bcp in. Please help me.
>

How to use bcp in at SQL Query analyzer

Dear All,
I need to do bcp in. The command I use at SQL Query
analyzer is
exec bcp 'schedule.dbo.emp_new'
out 'e:\sqlserver_bcp_data\new.out' -SSQLSERVER_TRY1 -Usa -
Ptrytry -c
But I am getting the error message
Server: Msg 179, Level 15, State 1, Line 1
Cannot use the OUTPUT option when passing a constant to a
stored procedure.
So, how to do bcp in. Please help me.BCP is a command line utility, not a T-SQL command. So, try that command
from the command prompt.
You could also invoked such executables from Query Analyzer, using the
xp_cmdshell extended system stored procedure. See SQL Server Books Online
for more information.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
"Sonia" <anonymous@.discussions.microsoft.com> wrote in message
news:2df0e01c46a5b$46289750$a301280a@.phx
.gbl...
Dear All,
I need to do bcp in. The command I use at SQL Query
analyzer is
exec bcp 'schedule.dbo.emp_new'
out 'e:\sqlserver_bcp_data\new.out' -SSQLSERVER_TRY1 -Usa -
Ptrytry -c
But I am getting the error message
Server: Msg 179, Level 15, State 1, Line 1
Cannot use the OUTPUT option when passing a constant to a
stored procedure.
So, how to do bcp in. Please help me.|||Hi,
You have to xp_cmdshell to execute a bcp from query analyzer.
master..xp_cmdshell 'bcp schedule.dbo.emp_new out
e:\sqlserver_bcp_data\new.out -SSQLSERVER_TRY1 -Usa -Ptrytry -c
Thanks
Hari
MCDBA
"Sonia" <anonymous@.discussions.microsoft.com> wrote in message
news:2df0e01c46a5b$46289750$a301280a@.phx
.gbl...
> Dear All,
> I need to do bcp in. The command I use at SQL Query
> analyzer is
> exec bcp 'schedule.dbo.emp_new'
> out 'e:\sqlserver_bcp_data\new.out' -SSQLSERVER_TRY1 -Usa -
> Ptrytry -c
> But I am getting the error message
> Server: Msg 179, Level 15, State 1, Line 1
> Cannot use the OUTPUT option when passing a constant to a
> stored procedure.
> So, how to do bcp in. Please help me.
>|||Sonia,
bcp is a commandline tool. To use it in QA you need to shell out and run
it using xp_cmdshell. Alternatively use BULK INSERT or DTS - the command
you posted actually bcps out, not in, so you need to change that.
example using xp_cmdshell:
exec master..xp_cmdshell 'bcp schedule.dbo.emp_new out
e:\sqlserver_bcp_data\new.out -SSQLSERVER_TRY1 -Usa -
Ptrytry -c'
--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Sonia wrote:
> Dear All,
> I need to do bcp in. The command I use at SQL Query
> analyzer is
> exec bcp 'schedule.dbo.emp_new'
> out 'e:\sqlserver_bcp_data\new.out' -SSQLSERVER_TRY1 -Usa -
> Ptrytry -c
> But I am getting the error message
> Server: Msg 179, Level 15, State 1, Line 1
> Cannot use the OUTPUT option when passing a constant to a
> stored procedure.
> So, how to do bcp in. Please help me.
>