Samples

Transact-SQL Samples

Samples

Samples

SQL Server 2000 provides programming samples that demonstrate how to use a number of different technologies with a variety of programming languages. You can install these as part of a custom installation.

You can use the following table to view all available samples, or you can select a specific category by clicking the Technology down arrow and making a specific selection (for example, Replication). You can also sort the table by clicking a column heading (for example, Language). To view detailed information about a specific sample, click the text in the Sample column.

ADO Employee MS-ITS:adosql.chm::/adoprg04_9nc9.htm Visual Basic Displays long data types using the Employees table in the Northwind database. ADO Employee MS-ITS:/adosql.chm::/adoprg04_1sa1.htm C++ Displays long data types using the Employees table in the Northwind database. ADO FORXML MS-ITS:adosql.chm::/adoprg04_92gc.htm XML Builds an Active Server Page (ASP) that retrieves result sets into streams. ADO Intro MS-ITS:adosql.chm::/adoprg04_5iw7.htm Visual Basic Connects to and queries a SQL Server database. Also shows error handling. ADO OpenXML MS-ITS:adosql.chm::/adoprg04_15ik.htm XML Builds an Active Server Page (ASP) that maps an XML schema to a relational schema. ADO Xpath MS-ITS:adosql.chm::/adoprg04_21vd.htm XML Builds an Active Server Page (ASP) that performs an xpath query. ADO Web MS-ITS:adosql.chm::/adoprg04_85ym.htm Web Builds Active Server Page (ASP)that interacts with instance of SQL Server. Analysis Services AspAdoComplex MS-ITS:olapdmpr.chm::/prsamples_1rji.htm VBScript Creates and manipulates a query-based cube. Analysis Services AspAdoCubeDoc MS-ITS:olapdmpr.chm::/prsamples_6p7y.htm VBSCript Retrieves and manipulates a cube schema. Analysis Services AspAdoCubeTree MS-ITS:olapdmpr.chm::/prsamples_6p7y.htm VBScript,JScript Retrieves and manipulates a cube schema. Analysis Services AspAdoSimple MS-ITS:olapdmpr.chm::/prsamples_1rji.htm VBScript Creates and manipulates a query-based cube. Analysis Services CppOlapDemo MS-ITS:olapdmpr.chm::/prsamples_1rji.htm C++ Creates and manipulates a query-based cube. Analysis Services VbAdoComplex MS-ITS:olapdmpr.chm::/prsamples_1rji.htm Visual Basic Creates and manipulates a query-based cube. Analysis Services VbAdoCreateCube MS-ITS:olapdmpr.chm::/prsamples_96zy.htm Visual Basic Creates a client-side cube. Analysis Services VbAdoCubeDoc MS-ITS:olapdmpr.chm::/prsamples_6p7y.htm Visual Basic Retrieves and manipulates a cube schema. Analysis Services VbAdoSimple MS-ITS:olapdmpr.chm::/prsamples_1rji.htm Visual Basic Creates and manipulates a query-based cube. Analysis Services VbDsoCreateSmallCube MS-ITS:olapdmpr.chm::/prsamples_63ou.htm Visual Basic Creates and manipulates a complex cube. Analysis Services VbDSOExample MS-ITS:olapdmpr.chm::/prsamples_96zy.htm Visual Basic Creates a server-side cube. Analysis Services VbAdoWriteBack MS-ITS:olapdmpr.chm::/prsamples_63ou.htm Visual Basic Creates and manipulates a complex cube. Analysis Services VbDsoWriteEnableCube MS-ITS:olapdmpr.chm::/prsamples_63ou.htm Visual Basic Creates and manipulates a complex cube. Analysis Services VbMdHTMLdll MS-ITS:olapdmpr.chm::/prsamples_63ou.htm Visual Basic Creates and manipulates a complex cube. DB Library Example8 MS-ITS:dblibc.chm::/dbc_db_csamp_3k6r.htm C++ Shows DB Library support for output parameters in Microsoft SQL Server stored procedures. DB Library Sqlexamp MS-ITS:dblibc.chm::/dbc_db_csamp_8gvn.htm C++ Shows how to handle various data types for consistent output. DB Library Sqltestc MS-ITS:dblibc.chm::/dbc_db_csamp_2tpj.htm C++ Issues a simple SELECT statement and prints the returned result set rows to the console. DB Library Sqltestn MS-ITS:dblibc.chm::/dbc_db_csamp_71pq.htm C++ Connects to a database and executes a SELECT statement from the Microsoft(r) Windows NT(r) graphical user interface. DB Library Textcopy MS-ITS:dblibc.chm::/dbc_db_csamp_67dt.htm C++ Illustrates how to handle Microsoft SQL Server text and image data types from a Microsoft Foundation Class (MFC) console. Desktop Engine Desktop Engine installlation MS-ITS:distsql.chm::/distsql_9zad.htm C++ Installs an instance of the Desktop Engine. DTS CustomTaskNoUI MS-ITS:dtsprog.chm::/dtspsamp_7u3t.htm Active Template Library (ATL) ATL template for a DTS custom task that does not support a custom user interface, but instead uses the default property grid in DTS Designer. DTS CustomTaskWithUI MS-ITS:dtsprog.chm::/dtspsamp_0dk9.htm Active Template Library (ATL) ATL template for a DTS custom task that supports a custom user interface. DTS CustomTransform MS-ITS:dtsprog.chm::/dtspsamp_9tkd.htm Active Template Library (ATL) ATL template for a DTS custom transformation. DTS DTSActiveScriptTask MS-ITS:dtsprog.chm::/dtspsamp_76p7.htm Visual Basic Runs a VBScript as part of a DTS Task. DTS DTSAppObject MS-ITS:dtsprog.chm::/dtspsamp_91ys.htm Visual Basic Uses DTS application object on the local server. DTS DTSApplicationObject MS-ITS:\dtsprog.chm::/dtspsamp_4a7o.htm Visual Basic Gets information from the DTS Application object. DTS DTSBulkInsertTask MS-ITS:dtsprog.chm::/dtspsamp_14iz.htm Visual Basic Uses DTS to do a Bulk Insert from a flat text file. DTS DTSCopy MS-ITS:dtsprog.chm::/dtspsamp_0k55.htm C++ Copies a single source column of any simple type into a destination column of the same type. DTS DTSCopyDatabase MS-ITS:dtsprog.chm::/dtspsamp_5pnp.htm Visual Basic Uses the DTS TransferObjectsTask object to copy a database. DTS DTSExecProcess MS-ITS:dtsprog.chm::/dtspsamp_9ik3.htm Visual Basic Runs a Win32 application from a DTS task. DTS DTSExecSQLTask MS-ITS:dtsprog.chm::/dtspsamp_2ip7.htm Visual Basic Executes a SQL statement while running a DTS package. DTS DTSExecutePackage MS-ITS:dtsprog.chm::/dtspsamp_6jvp.htm Visual Basic Executes programmatically a DTS package that has been saved to structured storage (i.e. .dts file). DTS DTSexmp1 MS-ITS:dtsprog.chm::/dtspsamp_5wvn.htm Visual Basic Copies data from a source table to a destination table. DTS DTSexmp2 MS-ITS:dtsprog.chm::/dtspsamp_7zcc.htm Visual Basic Copies database to Microsoft Excel spreadsheet and creates pivot table; also creates a DTS package. DTS DTSexmp3 MS-ITS:dtsprog.chm::/dtspsamp_3ur7.htm Visual Basic Creates a package supporting multiple sources and destinations. DTS DTSFTPTask MS-ITS:dtsprog.chm::/dtspsamp_6ai3.htm Visual Basic Uses DTS to copy files external to SQL Server from a source to a destination. DTS DTSPackageInfo MS-ITS:dtsprog.chm::/dtspsamp_5rov.htm Visual Basic Gets information using the DTS Application GetPackageInfos method. DTS DTSStrings MS-ITS:dtsprog.chm::/dtspsamp_47n7.htm C++ Reformats two source columns. DTS DTStask MS-ITS:dtsprog.chm::/dtspsamp_72qz.htm C++ Creates and registers a CreateProcessTask COM object. DTS DTSTransferObjectsTask MS-ITS:dtsprog.chm::/dtspsamp_65yj.htm Visual Basic Uses DTS to transfer various types of SQLServer objects from a pubs database to a pubs2 database. DTS DTSTskGVUpdate MS-ITS:dtsprog.chm::/dtspsamp_12lh.htm C++ Displays and allows the user to update the value of a global variable. DTS DTSTskPropIcon MS-ITS:dtsprog.chm::/dtspsamp_9f3i.htm C++ Displays a message whose text is specified as a custom task property. DTS DTSvbpkg MS-ITS:dtsprog.chm::/dtspsamp_5ns3.htm Visual Basic Builds and executes a DTS package. DTS DTSxform MS-ITS:dtsprog.chm::/dtspsamp_74h1.htm C++ Creates and registers a custom Transformation object. DTS FoodMart2000 MS-ITS:dtsprog.chm::/dtspsamp_7smo.htm Visual Basic Uses the Visual Basic file output from the DTS import/export wizard to convert the FoodMart 2000.mdb database to SQLServer. DTS Packages MS-ITS:dtsprog.chm::/dtspsamp_0f8z.htm C++ Creates and registers a custom Transformation object. DTS Pub2Pubs MS-ITS:dtsprog.chm::/dtspsamp_2m7n.htm Visual Basic Copies the authors table from the 'pubs' database to the 'pubs2' database, while doing some operations on various fields. Embedded SQL Edlib MS-ITS:esqlforc.chm::/ec_6_eex_00_9o36.htm C Uses GET CONNECTION to obtain the DB-Library DBPROCESS connection pointer. Embedded SQL Embedded SQL for C Examples MS-ITS:esqlforc.chm::/ec_6_eex_00_6376.htm C 8 examples using C to connect to a specified instance of MicrosoftSQL Server and execute a series of Embedded SQL statements. Embedded SQL Genchar MS-ITS:esqlforc.chm::/ec_6_eex_00_4uya.htm C Issues a SELECT statement query from the authors table in the pubs database. Embedded SQL Genwin MS-ITS:esqlforc.chm::/ec_6_eex_00_2a7m.htm C Issues a SELECT statement query from the authors table in the pubs database. Extended Stored Procedure xp-dblib MS-ITS:odssql.chm::/ods_6_sam_01_4xia.htm C Uses DB Library to open bound connection to same SQL Server that called the extended stored procedure. Extended Stored Procedure xp-hello MS-ITS:odssql.chm::/ods_6_sam_01_060f.htm C Displays "hellow world" in output row. Extended Stored Procedure xp-ODBC MS-ITS:odssql.chm::/ods_6_sam_01_9jkz.htm C Uses ODBC to open bound connection to same SQL Server that called the extended stored procedure. Extended Stored Procedure xp-param MS-ITS:odssql.chm::/ods_6_sam_01_4yel.htm C Accepts parameters from Transact-SQL script and reports values. MS DTC DB Library MS-ITS:samples.chm::/samp_msdtc_5a79.htm C++ Shows how to use MS-DTC in a C++ program. MS DTC ODBC MS-ITS:samples.chm::/samp_msdtc_5tnp.htm C++ Shows how to use MS-DTC in a C++ program, using ODBC. MS DTC T-SQL MS-ITS:samples.chm::/samp_msdtc_26hx.htm Transact-SQL Shows how to use MS-DTC in a Transact-SQL script. ODBC bcp MS-ITS:odbcsql.chm::/od_odbcsamp_4pm8.htm C++ Uses bulk copy functions with ODBC driver. ODBC Compute MS-ITS:odbcsql.chm::/od_odbcsamp_7yb7.htm C++ Executes SELECT statement, then determines shape of each result set generated. ODBC Loaddata MS-ITS:odbcsql.chm::/od_odbcsamp_74rl.htm C++ Loads data into SQL Server table. ODBC Mfcperf MS-ITS:odbcsql.chm::/od_odbcsamp_7xly.htm C++ Tunes MFC ODBC database classes for performance, and captures and interprets Microsoft SQL Server ODBC driver performance data. ODBC Trans MS-ITS:odbcsql.chm::/od_odbcsamp_8037.htm C++ Uses cursors to enable concurrent data access. OLE Automation Getnpv MS-ITS:samples.chm::/samp_oleauto_04md.htm Visual Basic Retrieves net present value. OLE Automation Loopback (DAO) MS-ITS:samples.chm::/samp_oleauto_7x45.htm Visual Basic Retrieves contents of the input table name provided to the DAO table and returns a tabular array equivalent to the result set returned from SQL Server. OLE Automation Loopback (RDO) MS-ITS:samples.chm::/samp_oleauto_5lyd.htm Visual Basic Uses RDO to call SQL Server and retrieve the contents of the authors table; returns a tabular array equivalent to the result set returned from SQL Server. OLE Automation Traverse MS-ITS:samples.chm::/samp_oleauto_5t2d.htm Transact-SQL Traverses an object hierarchy. Replication Deflt_sp MS-ITS:replprog.chm::/rp_replsamp_446q.htm Transact-SQL Builds a custom stored procedure resolver. Replication Distsamp MS-ITS:replprog.chm::/rp_replsamp_2pf2.htm C++ Shows how to include the SQL Merge and SQL Distribution controls in a custom application. Replication Repldts MS-ITS:replprog.chm::/rp_replsamp_3l0j.htm Visual Basic Creates a transformation subscription. Replication Replsamp MS-ITS:replprog.chm::/rp_replsamp_5uwe.htm HTML Shows how to include the SQL Merge and SQL Distribution controls in a custom application. Replication Replsamp.vbp MS-ITS:replprog.chm::/rp_replsamp_7yr2.htm Visual Basic Shows how to include the SQL Merge and SQL Distribution controls in a custom application. Replication Samppub MS-ITS:replprog.chm::/rp_replsamp_2mr3.htm Transact-SQL Configures a third-party publication and distributor. Replication Subspres MS-ITS:replprog.chm::/rp_replsamp_6p5x.htm C++ Builds a custom stored procedure resolver that executes the stored procedure at the Subscriber. Replication xp_enumntusers MS-ITS:replprog.chm::/rp_replsamp_3rsj.htm C++ Generates multiple merge dynamic snapshot jobs. SQL-DMO AxSQLDMOCtl MS-ITS:sqldmo.chm::/dmoref_ex01_3uy4.htm Visual Basic Creates a UserControl. SQL-DMO BackRestEvents MS-ITS:sqldmo.chm::/dmoref_ex01_0kix.htm Visual Basic Backs up and restores a database. SQL-DMO BackRestEvents MS-ITS:sqldmo.chm::/dmoref_ex01_01gp.htm C++ Backs up and restores a database. SQL-DMO BackupDevice MS-ITS:sqldmo.chm::/dmoref_ex01_325h.htm Visual Basic Uses BackupDevice object to add and remove a backup device. SQL-DMO CreateDatabase MS-ITS:sqldmo.chm::/dmoref_ex01_0bs5.htm Visual Basic Creates a database. SQL-DMO CreateTable MS-ITS:sqldmo.chm::/dmoref_ex01_5w11.htm Visual Basic Uses SQL-DMO objects to create and alter tables. SQL-DMO DMOExplorer MS-ITS:sqldmo.chm::/dmoref_ex01_53ci.htm Visual Basic Walks the DMO object model and shows the values in it. SQL-DMO Dmoping MS-ITS:sqldmo.chm::/dmoref_ex01_82pl.htm C++ Determines version of SQL Server instance. SQL-DMO Enums MS-ITS:sqldmo.chm::/dmoref_ex01_8roz.htm Visual Basic Uses SQL Server enumeration methods and recordsets. SQL-DMO Explore MS-ITS:sqldmo.chm::/dmoref_ex01_5a3p.htm Visual Basic Displays contents of collections and properties of objects in SQL-DMO object tree. SQL-DMO Idxtest MS-ITS:sqldmo.chm::/dmoref_ex01_3cc4.htm Visual Basic Tests optimization strategies for stored procedures and views. SQL-DMO Login MS-ITS:sqldmo.chm::/dmoref_ex01_0b72.htm Visual Basic Locates available SQL Servers and logs in to them. SQL-DMO Registry MS-ITS:sqldmo.chm::/dmoref_ex01_7gxl.htm Visual Basic Finds registry information about a specified SQL Server. SQL-DMO Service MS-ITS:sqldmo.chm::/dmoref_ex01_04yt.htm Visual Basic Checks status of, starts, and stops the service. SQL-DMO Smartptr MS-ITS:sqldmo.chm::/dmoref_ex01_07oy.htm C++ Uses Microsoft Visual C++ features to optimize size of program and speed of development. SQL-DMO Soc MS-ITS:sqldmo.chm::/dmoref_ex01_40tf.htm C Shows how to use C for SQL-DMO development. SQL-DMO Socpp MS-ITS:sqldmo.chm::/dmoref_ex01_74kw.htm C++ Shows how to use C++ for SQl-DMO development. SQL-DMO SQLScripts MS-ITS:sqldmo.chm::/dmoref_ex01_13sj.htm Visual Basic Shows how to generat SQL scripts to regenerate SQLServer objects. SQL-DMO VerifyBackup MS-ITS:sqldmo.chm::/dmoref_ex01_3t80.htm Visual Basic Finds backup devices and verifies backup set. SQL-NS Dbprop MS-ITS:sqlns.chm::/ns_samp_6x2a.htm C++ Displays Properties dialog for Pubs database. SQL-NS Dumptree MS-ITS:sqlns.chm::/ns_samp_5t7p.htm C++ Dumps all objects in the SQL namespace tree. SQL-NS Browse MS-ITS:sqlns.chm::/ns_samp_2h82.htm Visual Basic Creates browser for viewing and manipulating SQL namespace. SQL-NS Dbprop MS-ITS:sqlns.chm::/ns_samp_85gj.htm Visual Basic Displays Properties dialog for Pubs database. User Defined Functions CustNamesInRegion MS-ITS:samples.chm::/samples_1far.htm Transact-SQL Creates an in-line user-defined function in the Northwind database to view customer information for specific regions from the Customers table. User Defined Functions FindReports MS-ITS:samples.chm::/samples_1far.htm Transact-SQL Queries the Employees table in the Northwind database and shows all direct and indirect reports. User Defined Functions LargeFreight MS-ITS:samples.chm::/samples_1far.htm Transact-SQL Creates a user-defined function that queries the Shippers and Orders tables in the Northwind database and returns orders with freight greater than a certain value. User Defined Functions MyDate MS-ITS:samples.chm::/samples_1far.htm Transact-SQL Changes the format in which the date is returned Utilities Bii MS-ITS:samples.chm::/samples_2isp.htm Executable utiiity Mimics the bcp utility, but adds additional functinality. Utilities Pbalance MS-ITS:samples.chm::/samples_9h9h.htm C++ Displays process information for instances of Microsoft(r) SQL Server(tm) 2000 running on a local computer,and manages process priorities. Virtual Backup Device Mprocess MS-ITS:samples.chm::/samples_2p0z.htm C++ Demonstrates a multiple stream Backup or Restore, in which each stream is handled by a secondary process.. Virtual Backup Device Mthread MS-ITS:samples.chm::/samples_0b38.htm C++ Demonstrates a multiple stream Backup or Restore from a single process. Virtual Backup Device Osimple MS-ITS:samples.chm::/samples_2j51.htm C++ Demonstrates how to backup or restore a database across an ODBC connection. Virtual Backup Device Simple MS-ITS:samples.chm::/samples_4rfp.htm C++ Demonstrates how to backup or restore a database. Virtual Backup Device Snapshot MS-ITS:samples.chm::/samples_1kqc.htm C++ Demonstrates how to backup or restore a database using snapshot extensions. XML XMLDemo MS-ITS:samples.chm::/samples_6fj3.htm XML Demonstrates Microsoft(r) SQL Server(tm) 2000 support for XML. XML XMLStartup MS-ITS:samples.chm::/samples_0374.htm XML Demonstrates features that make SQL Server an XML-enabled database server.



 

New and updated SQL Server programming samples are available from the Microsoft Web site. On the Resources menu, click Code Center.

Note  When using the sample programs, ensure that hard-coded values, such as user name and password, are modified as necessary.