Friday, March 30, 2012

Need to create case sensitive Uniqiue Indexes

Hi,

How Can I create a case sensitive unique index so that A1 and a1 are treated
as different ?

I dont mind if I have to make a global DB change.

SteveSteve Thorpe (stephenthorpe@.nospam.hotmail.com) writes:
> How Can I create a case sensitive unique index so that A1 and a1 are
> treated as different ?
> I dont mind if I have to make a global DB change.

You should change the database to use a case-sensitive collation - and
maybe the entire server, since collation mix on the same server can
cause problems with tempdb.

You can achieve this in several ways. You can bulk out all data and
build a new database from scripts where you have changed the collation
and then bulk data back. You can also issue ALTER TABLE ALTER COLUMN
for all columns with character data. You also need to use ALTER COLLATION
SET COLLATION. (This latter command sets the default for future columns,
but does not affect existing ones.)

To change the collation for master, you use the rebuildm facility.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Need to create and access a SQL server database that will reside on an external hard drive

I need to create a SQL server database and add some tables to it. Then access it with a C# application. The problem is that the new SQL server database and it's tables must reside on an external hard drive. How do I point SQL server to this external drive, so that I can create a database on this drive and then create tables and access data on it?

Here are two articles with examples.

http://support.microsoft.com/default.aspx?scid=kb;en-us;q307283&id=kb;en-us;q307283&ln=en-us&rnk=1&sd=msdn&fr=0&qry=q307283&src=dhcs_mspss_msdn_srch&spr=msall

http://www.codeproject.com/cs/database/CreateDB.asp

|||

Hi Steve,

I am interested in setting this up through SQL Server management studio. Your refered links talk about doing it programatically. Neat stuff, but I need to do this through SQL Server management studio. Possibly someone has some more information on this?

|||

You can create a database locally, copy the mdf and ldf files to where you want them, and then attach to the files in the new location. Here is a link in the online help:

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/6732a431-cdef-4f1e-9262-4ac3b77c275e.htm

Or, right click the server icon and select properties.

Select the Database Settings Page. On that page you can specify what directories you want your data to be in.

|||Once the database and tables have been set up on the external drive, do you know if they can then be viewed and queried through SQL Server Query Analyzer?|||Once the database and tables have been set up on the external drive, do you know if they can then be viewed and queried through SQL Server Management Studio?|||

I tried what I suggested and it didn't work. The Management studio would not let me browse away from the PC it was installed on. I tried hard coding some paths to a remote drive but that didn't work.


Finally, I got this to work (from articlehttp://www.sqlteam.com/item.asp?ItemID=128)

DBCC TRACEON (1807);
GO

USE master;

GO
CREATE DATABASE Test
ON (FILENAME = '\\oak\C\temp\DataBase\SGWTest.mdf'),
(FILENAME = '\\oak\C\temp\DataBase\SGWTest_Log.ldf')
FOR ATTACH;
GO

Once attached, the database will act like any other database. However, I'm beginning to think Microsoft wants the engine and files to be on the same machine. It probably has something to do with performance and reliability :)

|||

Hi Steve. I am just getting back to your post. Thank you for your research and help on this. I am really greatfull to you. You have my vote for a Microsoft MVP! If I knew where to vote, I would vote for you.

I will read the article you suggested. With regards to the above script DBC TRACEON (1807) ...etc. Did you execute this as a SQL stored procedure?

If speed is an issue then I suppose I could always go with an external drive. It appears to me that possibly I can have a seperate instance of SQL server stored on this external drive, and then run that instance off of the external drive. The problem with this though is that I would have to power it up and down. Necessary I suppose if I want to have an external database.

Here is an example of a drive I was thinking about, if I had to go the route of getting an external hard drive.http://www.microcenter.com/byos/byos_single_product_results.phtml?product_id=249658

Talk to you later,

Ralph

sql

need to create a custom rendering format

Hi,
I am new to reporting service and I need to create a file of custom format except for thoese provided in RS,how to do it ? and I also want to put ths format in the dropdownlist in report manager , is there a way to do it?
Thanks a lot
--
Message posted via http://www.sqlmonster.comOn Sat, 22 Jan 2005 15:16:34 GMT, "angela chen via SQLMonster.com"
<forum@.SQLMonster.com> wrote:
>Hi,
>I am new to reporting service and I need to create a file of custom format except for thoese provided in RS,how to do it ? and I also want to put ths format in the dropdownlist in report manager , is there a way to do it?
>Thanks a lot
Yes, it is possible to create a custom rendering extension for RS.
Looks in the RS Books Online for more info. However, the task is not
trivial and, depending on your format, may require a major programming
effort.

Need to create <Query> statement programmatically

I am creating a web application that uses a using a web service to get data for my reports. Since the webservice only accepts 1 parameter called "sql" (the sql select statement), I am using the report's query string to get the data.

Here is the data source and dataset info I am using:

DataSource
Name: WebService
Type: XML
Connection string: http://localhost/myWeb/myWebService.asmx
Credentials: No credentials

DataSet
Query tab:
Name: WebService
Data source: WebService
Command type: Text
Query String: <Query><SoapAction>......</SoapAction></Query>

Here is a sample of the <Query> string that I use when I first build the report:

<Query>
<SoapAction>http://tempuri.org/GetDataset</SoapAction>
<Method Namespace="http://tempuri.org/" Name="GetDataset">
<Parameters>
<Parameter Name="sql" Type="String">
<DefaultValue>Select * From Customers</DefaultValue>
</Parameter>

</Parameters>
</Method>

<ElementPath IgnoreNamespaces="true">GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results</ElementPath>
</Query>

When the user selects a report in the web application, they are prompted for information about the sql statement, and then I can rebuild the <Query> xml fragment, substituting the new sql statemet for the default one. for example, the statement "Select * From Reports" would be replaced with "Select * From Customers where LN = 'Smith'".

Then I want to attach that new <Query> statement to the report and run it. How can I set this information in the report? I can't find anything that talks about it, but there must be some way!

Thanks in advance for your help!

Hi Videl,

There are a couple of ways you could accomplish this. But the best way is to take advantage of the QueryString being an expression. You could have the querystring reference a report parameter, and set this parameter to the new xml query with your web application when you run the report.

Example Dataset Query string: =Parameters!QueryParameter.Value

Or since you are just changing the sql query parameter, you could create a dataset parameter that references the report parameter. To do this you need to create a dataset parameter with the same name as the webmethod parameter. In this case, this would be sql. And the value for the dataset parameter would be the same expression above, only that in this case the value would just be the modified sql instead of the entire Xml query.

Another way is to directly modify the RDL and re-publish it, but this would not be very performant and would cause the report to be only useable by one user at a time.|||

Hi Ian,

OK, I set the dataset query string to Parameters!sql.Value, and created a report parameter called "sql". I set the default value of this parameter to :

="<Query><SoapAction>http://tempuri.org/GetDataset</SoapAction><Method Namespace='http://tempuri.org/' Name='GetDataset'><Parameters><Parameter Name='sql' Type='String'><DefaultValue>Select * From Reports</DefaultValue></Parameter></Parameters></Method><ElementPath IgnoreNamespaces='true'>GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results</ElementPath></Query>"

When I preview the report, I get the following error message:

An error occurred during local report processing. The definition of the report '/myReport/' is invalid. the Value expression for the textbox 'xyz' refers to the field 'xyz'. Report item expressions can only refer to fields within the current data set scope or, if inside an aggregate, the specified data set scope.

It looks like it is not finding the data before it tries to populate the fields on the report.

I also tried using a dataset paramter, and that looked maybe easier. I created a dataset parameter called sql, and set it's default value to the sql statement I want. Then I deleted the default value of the sql statement in the query statement, and ran it. I was prompted for the sql statement, and it ran fine. However, I am not sure how to set that value from code, since that is a dataset parameter and not a report parameter. That looks like an easier solution, but could you please tell me how to set that dataset parameter from my .NET code? Thanks!!!

Marlene

|||I think using a datset parameter is easier and less error prone, then dealing with the entire Xml query. However, you should be able to use the other approach. The reason you are getting the exception is that the fields are no longer defined in the dataset, since they were tied to the query. You need to manually add the fields to the dataset by right-clicking on the dataset in the Datasets panel in the Report Designer, and click add in the context menu.

Regarding your question, to set the dataset parameter programmatically, you need to use a report parameter as the value of the dataset parameter, like you did with the query expression, and set the report parameter in your call to create render the report.

Ian|||

Hi Ian,

I did as you suggested, manually adding the fields, and creating a reports parameter called "sql". Now the dataset parameter "sql" is set to Parameters!sql.value.

Now when I run the report, I get the right number of rows, but they are all blank. I have tried setting the field values to the dataset field value, and I have tried leaving them blank, and get the same results either way. How do I get them to mesh up?

|||Yes, they need to be mapped to the dataset field names. The issue you describe is usually caused by custom fields not being mapped to existing dataset fields. Can you make sure that the fields you are mapping to exist in the dataset returned by the Xml Query? Since this is a dataset being returned, can you try adding the following custom dataset field,

Name = RowID, DatabaseField = id

This should map RowID to the id attibute of the NewTable element. This also assumes that your ElementPath describes the path to the table level, without specifying the fields to retrieve. For example,

<ElementPath IgnoreNamespaces="true">GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results{}/NewTable</ElementPath>|||

Hi,

I didn't quite understand that.

I do have the <ElementPath> tag that you described in my <query> string, except it is slightly different:

<ElementPath IgnoreNamespaces="true">GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results</ElementPath

When I replaced /Results with /Results{}/NewTable, data was no longer returned to the dataset, so I changed it back.

I added a dataset field named "RowID", set it's type to "Database Field" and set the value to "=id" (I did not type in the quotes). However the data still did not display.

FYI, here is the entire query string I am using. I include it since it includes that elementPath part that stubbornly refuses to play nice with NewTable:
-

<Query>
<SoapAction>http://tempuri.org/GetDataset</SoapAction>
<Method Namespace="http://tempuri.org/" Name="GetDataset">
<Parameters>
<Parameter Name="sql" Type="String">
<DefaultValue></DefaultValue>
</Parameter>
</Parameters>
</Method>
<ElementPath IgnoreNamespaces="true">GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results</ElementPath>
</Query>
-
Here is a sample output from my webservice
-
<?xml version="1.0" encoding="utf-8" ?>

- <DataSet xmlns="http://tempuri.org/">

- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">

- <xs:complexType>

- <xs:choice minOccurs="0" maxOccurs="unbounded">

- <xs:element name="Results">

- <xs:complexType>

- <xs:sequence>

<xs:element name="ReportID" type="xs:int" minOccurs="0" />

<xs:element name="ReportName" type="xs:string" minOccurs="0" />

<xs:element name="ReportFriendlyName" type="xs:string" minOccurs="0" />

<xs:element name="ReportDescription" type="xs:string" minOccurs="0" />

<xs:element name="Display" type="xs:boolean" minOccurs="0" />

<xs:element name="DataViewName" type="xs:string" minOccurs="0" />

<xs:element name="Example1" type="xs:boolean" minOccurs="0" />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:choice>

</xs:complexType>

</xs:element>

</xs:schema>

- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">

- <NewDataSet xmlns="">

- <Results diffgr:id="Results1" msdata:rowOrder="0">

<ReportID>10</ReportID>

<ReportName>Reports_ByReportID1</ReportName>

<ReportFriendlyName>Reports by ID, w/ Dataset Parameter</ReportFriendlyName>

<ReportDescription>List of reports by report ID. This example uses a dataset parameter, which is referenced in the query string.</ReportDescription>

<Display>true</Display>

<DataViewName>Reports</DataViewName>

<Example1>false</Example1>

</Results>

</NewDataSet>

</diffgr:diffgram>

</DataSet>
--

And here are all my dataset fields:

FieldName Type Value
ReportID Database field =Fields!ReportID.Value
ReportName Database field =Fields!ReportName.Value
ReportFriendlyName Database field =Fields!ReportFriendlyName.Value

RowID Database field =id

|||Your element path is correct--you are describing the relationships to the table level. I mixed the name of your table, Results, with that of my dataset, also Results.

When creating custom Dataset fields, the value should be just the database field name. The value in the field is treated as a literal, so Reporting services is trying to match your custom dataset field, ReportID, to a field from the dataset returned from the query named "=Fields!ReportID.Value"

Try using these custom dataset field.

FieldNameType ValueReportIDDatabase field ReportIDReportNameDatabase field ReportNameReportFriendlyNameDatabase field ReportFriendlyName

More information on custom dataset fields:
http://msdn2.microsoft.com/en-us/library/ms189677.aspx|||You are the best!!!! |||When manually defining the fields in the dataset (e.g. programmatic select statement), how do you get them to 'stick'? When previewing the report, they get wiped out of the dataset once in a while.
sql

Need to create <Query> statement programmatically

I am creating a web application that uses a using a web service to get data for my reports. Since the webservice only accepts 1 parameter called "sql" (the sql select statement), I am using the report's query string to get the data.

Here is the data source and dataset info I am using:

DataSource
Name: WebService
Type: XML
Connection string: http://localhost/myWeb/myWebService.asmx
Credentials: No credentials

DataSet
Query tab:
Name: WebService
Data source: WebService
Command type: Text
Query String: <Query><SoapAction>......</SoapAction></Query>

Here is a sample of the <Query> string that I use when I first build the report:

<Query>
<SoapAction>http://tempuri.org/GetDataset</SoapAction>
<Method Namespace="http://tempuri.org/" Name="GetDataset">
<Parameters>
<Parameter Name="sql" Type="String">
<DefaultValue>Select * From Customers</DefaultValue>
</Parameter>

</Parameters>
</Method>

<ElementPath IgnoreNamespaces="true">GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results</ElementPath>
</Query>

When the user selects a report in the web application, they are prompted for information about the sql statement, and then I can rebuild the <Query> xml fragment, substituting the new sql statemet for the default one. for example, the statement "Select * From Reports" would be replaced with "Select * From Customers where LN = 'Smith'".

Then I want to attach that new <Query> statement to the report and run it. How can I set this information in the report? I can't find anything that talks about it, but there must be some way!

Thanks in advance for your help!

Hi Videl,

There are a couple of ways you could accomplish this. But the best way is to take advantage of the QueryString being an expression. You could have the querystring reference a report parameter, and set this parameter to the new xml query with your web application when you run the report.

Example Dataset Query string: =Parameters!QueryParameter.Value

Or since you are just changing the sql query parameter, you could create a dataset parameter that references the report parameter. To do this you need to create a dataset parameter with the same name as the webmethod parameter. In this case, this would be sql. And the value for the dataset parameter would be the same expression above, only that in this case the value would just be the modified sql instead of the entire Xml query.

Another way is to directly modify the RDL and re-publish it, but this would not be very performant and would cause the report to be only useable by one user at a time.|||

Hi Ian,

OK, I set the dataset query string to Parameters!sql.Value, and created a report parameter called "sql". I set the default value of this parameter to :

="<Query><SoapAction>http://tempuri.org/GetDataset</SoapAction><Method Namespace='http://tempuri.org/' Name='GetDataset'><Parameters><Parameter Name='sql' Type='String'><DefaultValue>Select * From Reports</DefaultValue></Parameter></Parameters></Method><ElementPath IgnoreNamespaces='true'>GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results</ElementPath></Query>"

When I preview the report, I get the following error message:

An error occurred during local report processing. The definition of the report '/myReport/' is invalid. the Value expression for the textbox 'xyz' refers to the field 'xyz'. Report item expressions can only refer to fields within the current data set scope or, if inside an aggregate, the specified data set scope.

It looks like it is not finding the data before it tries to populate the fields on the report.

I also tried using a dataset paramter, and that looked maybe easier. I created a dataset parameter called sql, and set it's default value to the sql statement I want. Then I deleted the default value of the sql statement in the query statement, and ran it. I was prompted for the sql statement, and it ran fine. However, I am not sure how to set that value from code, since that is a dataset parameter and not a report parameter. That looks like an easier solution, but could you please tell me how to set that dataset parameter from my .NET code? Thanks!!!

Marlene

|||I think using a datset parameter is easier and less error prone, then dealing with the entire Xml query. However, you should be able to use the other approach. The reason you are getting the exception is that the fields are no longer defined in the dataset, since they were tied to the query. You need to manually add the fields to the dataset by right-clicking on the dataset in the Datasets panel in the Report Designer, and click add in the context menu.

Regarding your question, to set the dataset parameter programmatically, you need to use a report parameter as the value of the dataset parameter, like you did with the query expression, and set the report parameter in your call to create render the report.

Ian|||

Hi Ian,

I did as you suggested, manually adding the fields, and creating a reports parameter called "sql". Now the dataset parameter "sql" is set to Parameters!sql.value.

Now when I run the report, I get the right number of rows, but they are all blank. I have tried setting the field values to the dataset field value, and I have tried leaving them blank, and get the same results either way. How do I get them to mesh up?

|||Yes, they need to be mapped to the dataset field names. The issue you describe is usually caused by custom fields not being mapped to existing dataset fields. Can you make sure that the fields you are mapping to exist in the dataset returned by the Xml Query? Since this is a dataset being returned, can you try adding the following custom dataset field,

Name = RowID, DatabaseField = id

This should map RowID to the id attibute of the NewTable element. This also assumes that your ElementPath describes the path to the table level, without specifying the fields to retrieve. For example,

<ElementPath IgnoreNamespaces="true">GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results{}/NewTable</ElementPath>|||

Hi,

I didn't quite understand that.

I do have the <ElementPath> tag that you described in my <query> string, except it is slightly different:

<ElementPath IgnoreNamespaces="true">GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results</ElementPath

When I replaced /Results with /Results{}/NewTable, data was no longer returned to the dataset, so I changed it back.

I added a dataset field named "RowID", set it's type to "Database Field" and set the value to "=id" (I did not type in the quotes). However the data still did not display.

FYI, here is the entire query string I am using. I include it since it includes that elementPath part that stubbornly refuses to play nice with NewTable:
-

<Query>
<SoapAction>http://tempuri.org/GetDataset</SoapAction>
<Method Namespace="http://tempuri.org/" Name="GetDataset">
<Parameters>
<Parameter Name="sql" Type="String">
<DefaultValue></DefaultValue>
</Parameter>
</Parameters>
</Method>
<ElementPath IgnoreNamespaces="true">GetDatasetResponse{}/GetDatasetResult{}/diffgram{}/NewDataSet{}/Results</ElementPath>
</Query>
-
Here is a sample output from my webservice
-
<?xml version="1.0" encoding="utf-8" ?>

- <DataSet xmlns="http://tempuri.org/">

- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">

- <xs:complexType>

- <xs:choice minOccurs="0" maxOccurs="unbounded">

- <xs:element name="Results">

- <xs:complexType>

- <xs:sequence>

<xs:element name="ReportID" type="xs:int" minOccurs="0" />

<xs:element name="ReportName" type="xs:string" minOccurs="0" />

<xs:element name="ReportFriendlyName" type="xs:string" minOccurs="0" />

<xs:element name="ReportDescription" type="xs:string" minOccurs="0" />

<xs:element name="Display" type="xs:boolean" minOccurs="0" />

<xs:element name="DataViewName" type="xs:string" minOccurs="0" />

<xs:element name="Example1" type="xs:boolean" minOccurs="0" />

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:choice>

</xs:complexType>

</xs:element>

</xs:schema>

- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">

- <NewDataSet xmlns="">

- <Results diffgr:id="Results1" msdata:rowOrder="0">

<ReportID>10</ReportID>

<ReportName>Reports_ByReportID1</ReportName>

<ReportFriendlyName>Reports by ID, w/ Dataset Parameter</ReportFriendlyName>

<ReportDescription>List of reports by report ID. This example uses a dataset parameter, which is referenced in the query string.</ReportDescription>

<Display>true</Display>

<DataViewName>Reports</DataViewName>

<Example1>false</Example1>

</Results>

</NewDataSet>

</diffgr:diffgram>

</DataSet>
--

And here are all my dataset fields:

FieldName Type Value
ReportID Database field =Fields!ReportID.Value
ReportName Database field =Fields!ReportName.Value
ReportFriendlyName Database field =Fields!ReportFriendlyName.Value

RowID Database field =id

|||Your element path is correct--you are describing the relationships to the table level. I mixed the name of your table, Results, with that of my dataset, also Results.

When creating custom Dataset fields, the value should be just the database field name. The value in the field is treated as a literal, so Reporting services is trying to match your custom dataset field, ReportID, to a field from the dataset returned from the query named "=Fields!ReportID.Value"

Try using these custom dataset field.

FieldNameType ValueReportIDDatabase field ReportIDReportNameDatabase field ReportNameReportFriendlyNameDatabase field ReportFriendlyName

More information on custom dataset fields:
http://msdn2.microsoft.com/en-us/library/ms189677.aspx|||You are the best!!!! |||When manually defining the fields in the dataset (e.g. programmatic select statement), how do you get them to 'stick'? When previewing the report, they get wiped out of the dataset once in a while.

Need to count and group in units of ten

ok
well this seems easy enough so here it is.
I have a list of some 131500 records with 98 distinct employees thus there are several thousand records per employee. I am using reporting services and I need to set up the graph in units of ten. Having 98 employees on one graph will not work so I need to break them up in units of ten. I can't seem to remember the sql I need to write to accomplish this

any thoughts?
km

Assuming you are using sql server 2005, Can you try using

row_number() over (order by employee_id) as EmpIndex

for getting unique IDs and then split them based on EmpIndex/10=1, ...=9 etc.

|||

I 'think' that it would be far easier to help you if you could provide the table DDL, some sample data in the form of INSERT statements, and a display of your desired results.

For help with that, check:http://www.aspfaq.com/5006

|||thanks for the quick response-- here is some of the sql I have been playing with

SELECT
PH_ado_dac_no as DacNumber,
PH_ado_bimon as BillMonth,
PH_ado_biyr as BillYear,
[GH2_GroupName_(_ado_Bill_seq_no_)]as BillSeqNumber,
[PH_GroupName_(_ado_subscriber_no_)],
GH3_ado_unt as Unt_Employee,
DE_ado_CHANNEL_SEIZURE_DT as ChannelSeizureDate,
DE_ado_tim as ChannelSeizureTime,
DE_ado_CALL_TO_CITY_DESC as Call_To_City,
DE_ado_CALL_TO_STATE_CODE as Call_To_State,
DE_ado_tn as Number_To_From,
DE_checkserv AS CallDurationMinSec,
ROW_NUMBER() OVER(ORDER BY GH3_ado_unt ASC)/10 AS 'groupID',
DE_ado_at_charge_amt as Usage_At_Charge_Amt,
DE_ado_toll_charge_amt AS LongDistance_Toll_Charge_Amt,
DE_ado_tot as Total,
GF3_checkservtot as TotalCheckServe,
GF3_Total as TotalMins,
GF3_ac as TotalLongDistanceCharge
FROM
[cdtable1]

GROUP BY
PH_ado_dac_no,
'groupID'

this looks like something I have been trying to use but does not give the desired results since there may be hundreds of entries within the dataset with the same emp_id. when I use row_number() over (order by employee_id) as EmpIndex /10, the same person has multiple EmpIndex's-- I need each employee to have one and only one EmpIndex and group those in units of ten.
thanks again
km

|||thanks for the response-- I posted some additional information to the post previous to yours

km
|||

I should have mentioned this, sorry, can you add partition by inside the Over() clause.

row_number() over ( partition by employee_id order by employee_id)

|||Great this is looking much better
appreciate your help :-)
km

Need to copy All oracle tables to SQL Server 2005

I am racking my brain on this one. I am migrating Oracle data to SQL Server and would like an SSIS package that will copy the oracle data from every table to SQL server. I already have the schema set up in SQL and a straight copy of a specified table works fine between the OLEDB source and OLEDB destination. However, when I set up a loop which sets a global variable for the table names, which are identical on both dbs, and try to set the OLEDB Source and Destination OpenRowsetVariable to the global variable, the process fails with these errors with all validation turned off:

[OLE DB Source [18]] Warning: Cannot retrieve the column code page info from the OLE DB provider. If the component supports the "DefaultCodePage" property, the code page from that property will be used. Change the value of the property if the current string code page values are incorrect. If the component does not support the property, the code page from the component's locale ID will be used.

[OLE DB Source [18]] Error: Column "ID" cannot be found at the datasource.

[DTS.Pipeline] Error: component "OLE DB Source" (18) failed the pre-execute phase and returned error code 0xC0202005.

To sum up, I want to set the tables dynamically and have them infer the mappings. The names of the columns are already the exact same on each schema, and the data types are mapped accordingly. I have already verified that the names of the tables have been formatted correctly for each database. If I can't do it this way then how?

You can't change the source at run-time since the Meta-data for the columns is static.

To do a copy like this, you need to have a seperate source and destination for each table. The easiest way to do this is to use the Import/Export wizard in 2005 to generate the package. Select the target database in SSMS, right click it and pick Tasks/Import data to run the wizard. it should be pretty self-explanatory, but, if you have trouble, there is a good section on it in BOL.

|||

swatts777 wrote:

[OLE DB Source [18]] Warning: Cannot retrieve the column code page info from the OLE DB provider. If the component supports the "DefaultCodePage" property, the code page from that property will be used. Change the value of the property if the current string code page values are incorrect. If the component does not support the property, the code page from the component's locale ID will be used.

This warning can easily be fixed by setting AlwaysUseDefaultCodePage=TRUE on the OLE DB Source component.

swatts777 wrote:

To sum up, I want to set the tables dynamically and have them infer the mappings. The names of the columns are already the exact same on each schema, and the data types are mapped accordingly. I have already verified that the names of the tables have been formatted correctly for each database. If I can't do it this way then how?

SSIS won't do this. I'm worried that you might have read some documentation somewhere that led you think that it will. Is that the case?

Like David said, you have to build a data-flow for each table. You could make it easy on yourself and get the import/export wizard to build it for you.

-Jamie

-Jamie

|||

Apparently, my Oracle Provider wasn't registered in SQL, so I did not know I had this option avalable to me. Using Microsoft's OLEDB Provider for Oracle only lets you pull data over using custom queries. I restarted SQL and my oracle provider showed up. WOW! Thanks for all your help, this worked great! I was able to go through each table and map datatypes and everything. Then I saved the whole thing as an SSIS package for use when we go live.

|||

Hi swatts777,

Can you(or anyone else) tell me how to register an Oracle provider as you described above?
i am having the same endless shyte with data types when pulling single values from Oracle.

Anybody please help me

Regards,

Pieter

|||

I think yhe answer is right there...

swatts777 wrote:

I restarted SQL and my oracle provider showed up.

|||

Hi Rafael,

It seems pretty much easy doesn't it, but I'm still not sure if I should have a new version of Oracle installed before I restart my SQL server or install just a driver or what?

Maybe I should change my name to StupidPete?

Regards,

Pieter

|||

Peter,

After installing the Oracle client, you must set up Oracle Net services to point to the correct Oracle database. There are plenty of articles on doing this. You should have installed the Client using Oracle Universal Installer that comes with the client you are using and that you downloaded from Oracle's site. If you have done all of this, then you can restart the machine. That is the best way. If you are using SQL Server 2005, under Server Objects>Linked Servers>Providers you should now see a OraOLEDB.Oracle provider listed. Now you may create your Linked server using this provider instead of MSADORA.

Hope this helps,

Shawn

|||

CleverPete wrote:

Hi Rafael,

It seems pretty much easy doesn't it, but I'm still not sure if I should have a new version of Oracle installed before I restart my SQL server or install just a driver or what?

Maybe I should change my name to StupidPete?

Regards,

Pieter

This is a perfect example of how a flamming thread starts and how they get deleted/locked. I just wanted to point out a detail that you could have miss. BTW, that was quite the answer; just install it and re-start the machine.

Rafael Salas wrote:

I think yhe answer is right there...

swatts777 wrote:

I restarted SQL and my oracle provider showed up.

|||I wasn't really focused on the questions being asked, rather my on experiences in dealing with the problems I faced. I will try to answer questions more precise and pay more attention to the actual questions being posted.|||

I am trying to do the same exact thing, but with a CACHE database, not oracle. My issue is that SSIS will not dynamically map the columns from each new table that I setup in a foreach loop. I do not want to create a separate design time mapping for each table (there are lots of tables). If I cannot figure this out, I will use OPENQUERY with a linked server, and set the OPENQUERY string dynamically in a loop. Unless I misunderstood, you are not dynamically writing to tables with different structures, correct? If so, how did you get that to work?

|||

Dave Dumas wrote:

I am trying to do the same exact thing, but with a CACHE database, not oracle. My issue is that SSIS will not dynamically map the columns from each new table that I setup in a foreach loop.

You're right, it doesn't do this. You can't do what you are attempting unless the columns in all the source tables are the same.

Dave Dumas wrote:

I do not want to create a separate design time mapping for each table (there are lots of tables).

Unfortunately if you want to use data-flows this is your only option.

Dave Dumas wrote:

If I cannot figure this out, I will use OPENQUERY with a linked server, and set the OPENQUERY string dynamically in a loop.

Good idea that. Let us know how it goes.

-Jamie

|||

Thanks Jamie. What I did (since the OPENQUERY syntax does not all variables, only strings), was to write a select statement with dynamic sql as output. I outputted 300 OPENQUERY statements inside of try-catch BEGIN END blocks. This worked great. - Dave

Need to copy All oracle tables to SQL Server 2005

I am racking my brain on this one. I am migrating Oracle data to SQL Server and would like an SSIS package that will copy the oracle data from every table to SQL server. I already have the schema set up in SQL and a straight copy of a specified table works fine between the OLEDB source and OLEDB destination. However, when I set up a loop which sets a global variable for the table names, which are identical on both dbs, and try to set the OLEDB Source and Destination OpenRowsetVariable to the global variable, the process fails with these errors with all validation turned off:

[OLE DB Source [18]] Warning: Cannot retrieve the column code page info from the OLE DB provider. If the component supports the "DefaultCodePage" property, the code page from that property will be used. Change the value of the property if the current string code page values are incorrect. If the component does not support the property, the code page from the component's locale ID will be used.

[OLE DB Source [18]] Error: Column "ID" cannot be found at the datasource.

[DTS.Pipeline] Error: component "OLE DB Source" (18) failed the pre-execute phase and returned error code 0xC0202005.

To sum up, I want to set the tables dynamically and have them infer the mappings. The names of the columns are already the exact same on each schema, and the data types are mapped accordingly. I have already verified that the names of the tables have been formatted correctly for each database. If I can't do it this way then how?

You can't change the source at run-time since the Meta-data for the columns is static.

To do a copy like this, you need to have a seperate source and destination for each table. The easiest way to do this is to use the Import/Export wizard in 2005 to generate the package. Select the target database in SSMS, right click it and pick Tasks/Import data to run the wizard. it should be pretty self-explanatory, but, if you have trouble, there is a good section on it in BOL.

|||

swatts777 wrote:

[OLE DB Source [18]] Warning: Cannot retrieve the column code page info from the OLE DB provider. If the component supports the "DefaultCodePage" property, the code page from that property will be used. Change the value of the property if the current string code page values are incorrect. If the component does not support the property, the code page from the component's locale ID will be used.

This warning can easily be fixed by setting AlwaysUseDefaultCodePage=TRUE on the OLE DB Source component.

swatts777 wrote:

To sum up, I want to set the tables dynamically and have them infer the mappings. The names of the columns are already the exact same on each schema, and the data types are mapped accordingly. I have already verified that the names of the tables have been formatted correctly for each database. If I can't do it this way then how?

SSIS won't do this. I'm worried that you might have read some documentation somewhere that led you think that it will. Is that the case?

Like David said, you have to build a data-flow for each table. You could make it easy on yourself and get the import/export wizard to build it for you.

-Jamie

-Jamie

|||

Apparently, my Oracle Provider wasn't registered in SQL, so I did not know I had this option avalable to me. Using Microsoft's OLEDB Provider for Oracle only lets you pull data over using custom queries. I restarted SQL and my oracle provider showed up. WOW! Thanks for all your help, this worked great! I was able to go through each table and map datatypes and everything. Then I saved the whole thing as an SSIS package for use when we go live.

|||

Hi swatts777,

Can you(or anyone else) tell me how to register an Oracle provider as you described above?
i am having the same endless shyte with data types when pulling single values from Oracle.

Anybody please help me

Regards,

Pieter

|||

I think yhe answer is right there...

swatts777 wrote:

I restarted SQL and my oracle provider showed up.

|||

Hi Rafael,

It seems pretty much easy doesn't it, but I'm still not sure if I should have a new version of Oracle installed before I restart my SQL server or install just a driver or what?

Maybe I should change my name to StupidPete?

Regards,

Pieter

|||

Peter,

After installing the Oracle client, you must set up Oracle Net services to point to the correct Oracle database. There are plenty of articles on doing this. You should have installed the Client using Oracle Universal Installer that comes with the client you are using and that you downloaded from Oracle's site. If you have done all of this, then you can restart the machine. That is the best way. If you are using SQL Server 2005, under Server Objects>Linked Servers>Providers you should now see a OraOLEDB.Oracle provider listed. Now you may create your Linked server using this provider instead of MSADORA.

Hope this helps,

Shawn

|||

CleverPete wrote:

Hi Rafael,

It seems pretty much easy doesn't it, but I'm still not sure if I should have a new version of Oracle installed before I restart my SQL server or install just a driver or what?

Maybe I should change my name to StupidPete?

Regards,

Pieter

This is a perfect example of how a flamming thread starts and how they get deleted/locked. I just wanted to point out a detail that you could have miss. BTW, that was quite the answer; just install it and re-start the machine.

Rafael Salas wrote:

I think yhe answer is right there...

swatts777 wrote:

I restarted SQL and my oracle provider showed up.

|||I wasn't really focused on the questions being asked, rather my on experiences in dealing with the problems I faced. I will try to answer questions more precise and pay more attention to the actual questions being posted.|||

I am trying to do the same exact thing, but with a CACHE database, not oracle. My issue is that SSIS will not dynamically map the columns from each new table that I setup in a foreach loop. I do not want to create a separate design time mapping for each table (there are lots of tables). If I cannot figure this out, I will use OPENQUERY with a linked server, and set the OPENQUERY string dynamically in a loop. Unless I misunderstood, you are not dynamically writing to tables with different structures, correct? If so, how did you get that to work?

|||

Dave Dumas wrote:

I am trying to do the same exact thing, but with a CACHE database, not oracle. My issue is that SSIS will not dynamically map the columns from each new table that I setup in a foreach loop.

You're right, it doesn't do this. You can't do what you are attempting unless the columns in all the source tables are the same.

Dave Dumas wrote:

I do not want to create a separate design time mapping for each table (there are lots of tables).

Unfortunately if you want to use data-flows this is your only option.

Dave Dumas wrote:

If I cannot figure this out, I will use OPENQUERY with a linked server, and set the OPENQUERY string dynamically in a loop.

Good idea that. Let us know how it goes.

-Jamie

|||

Thanks Jamie. What I did (since the OPENQUERY syntax does not all variables, only strings), was to write a select statement with dynamic sql as output. I outputted 300 OPENQUERY statements inside of try-catch BEGIN END blocks. This worked great. - Dave

Need to copy a database in the same server without using backup re

Hi,
I need to copy a database 'management' in the same server and name it as management_mid. Is there any command or script to copy the database without
using the backup restore operation? Thanks in advance.
Use a DTS package.
Bobby Ryzhy
bobby@. name of domain below
http://www.weekendtech.net
On Tue, 6 Jul 2004 15:34:01 -0700, "Jack"
<Jack@.discussions.microsoft.com> wrote:

>Hi,
>I need to copy a database 'management' in the same server and name it as management_mid. Is there any command or script to copy the database without
>using the backup restore operation? Thanks in advance.
|||WHat is wrong with Backup and Restore? You can Restore to a different name
and location. You can also try sp_attach_db.
Andrew J. Kelly SQL MVP
"Jack" <Jack@.discussions.microsoft.com> wrote in message
news:4B8B3A20-69CC-46F2-A9C3-3009FE770FEE@.microsoft.com...
> Hi,
> I need to copy a database 'management' in the same server and name it as
management_mid. Is there any command or script to copy the database without
> using the backup restore operation? Thanks in advance.
|||Hi,
Use this below list of commands, But it require a minutes down time for
actual database.
sp_detach_db management
go
copy the MDF and LDF file for management database to a different folder
go
-- attach the original database management
sp_attach_db
'management','physical_mdf_file_with_path','plysic al_ldf_with_path'
go
--attach the new database
sp_attach_db
'management_mid','physical_mdf_file_with_path','pl ysical_ldf_with_path'
Note:
DTS/BCP are also possible , but will take long time. It requires some manual
tasks as well.
Thanks
Hari
MCDBA
"Jack" <Jack@.discussions.microsoft.com> wrote in message
news:4B8B3A20-69CC-46F2-A9C3-3009FE770FEE@.microsoft.com...
> Hi,
> I need to copy a database 'management' in the same server and name it as
management_mid. Is there any command or script to copy the database without
> using the backup restore operation? Thanks in advance.
sql

Need to copy a database in the same server without using backup re

Hi,
I need to copy a database 'management' in the same server and name it as management_mid. Is there any command or script to copy the database without
using the backup restore operation? Thanks in advance.Use a DTS package.
Bobby Ryzhy
bobby@. name of domain below
http://www.weekendtech.net
On Tue, 6 Jul 2004 15:34:01 -0700, "Jack"
<Jack@.discussions.microsoft.com> wrote:
>Hi,
>I need to copy a database 'management' in the same server and name it as management_mid. Is there any command or script to copy the database without
>using the backup restore operation? Thanks in advance.|||WHat is wrong with Backup and Restore? You can Restore to a different name
and location. You can also try sp_attach_db.
--
Andrew J. Kelly SQL MVP
"Jack" <Jack@.discussions.microsoft.com> wrote in message
news:4B8B3A20-69CC-46F2-A9C3-3009FE770FEE@.microsoft.com...
> Hi,
> I need to copy a database 'management' in the same server and name it as
management_mid. Is there any command or script to copy the database without
> using the backup restore operation? Thanks in advance.|||Hi,
Use this below list of commands, But it require a minutes down time for
actual database.
sp_detach_db management
go
copy the MDF and LDF file for management database to a different folder
go
-- attach the original database management
sp_attach_db
'management','physical_mdf_file_with_path','plysical_ldf_with_path'
go
--attach the new database
sp_attach_db
'management_mid','physical_mdf_file_with_path','plysical_ldf_with_path'
Note:
DTS/BCP are also possible , but will take long time. It requires some manual
tasks as well.
--
Thanks
Hari
MCDBA
"Jack" <Jack@.discussions.microsoft.com> wrote in message
news:4B8B3A20-69CC-46F2-A9C3-3009FE770FEE@.microsoft.com...
> Hi,
> I need to copy a database 'management' in the same server and name it as
management_mid. Is there any command or script to copy the database without
> using the backup restore operation? Thanks in advance.

Need to copy a database in the same server without using backup re

Hi,
I need to copy a database 'management' in the same server and name it as man
agement_mid. Is there any command or script to copy the database without
using the backup restore operation? Thanks in advance.Use a DTS package.
Bobby Ryzhy
bobby@. name of domain below
http://www.weekendtech.net
On Tue, 6 Jul 2004 15:34:01 -0700, "Jack"
<Jack@.discussions.microsoft.com> wrote:

>Hi,
>I need to copy a database 'management' in the same server and name it as ma
nagement_mid. Is there any command or script to copy the database without
>using the backup restore operation? Thanks in advance.|||WHat is wrong with Backup and Restore? You can Restore to a different name
and location. You can also try sp_attach_db.
Andrew J. Kelly SQL MVP
"Jack" <Jack@.discussions.microsoft.com> wrote in message
news:4B8B3A20-69CC-46F2-A9C3-3009FE770FEE@.microsoft.com...
> Hi,
> I need to copy a database 'management' in the same server and name it as
management_mid. Is there any command or script to copy the database without
> using the backup restore operation? Thanks in advance.|||Hi,
Use this below list of commands, But it require a minutes down time for
actual database.
sp_detach_db management
go
copy the MDF and LDF file for management database to a different folder
go
-- attach the original database management
sp_attach_db
'management','physical_mdf_file_with_pat
h','plysical_ldf_with_path'
go
--attach the new database
sp_attach_db
'management_mid','physical_mdf_file_with
_path','plysical_ldf_with_path'
Note:
DTS/BCP are also possible , but will take long time. It requires some manual
tasks as well.
--
Thanks
Hari
MCDBA
"Jack" <Jack@.discussions.microsoft.com> wrote in message
news:4B8B3A20-69CC-46F2-A9C3-3009FE770FEE@.microsoft.com...
> Hi,
> I need to copy a database 'management' in the same server and name it as
management_mid. Is there any command or script to copy the database without
> using the backup restore operation? Thanks in advance.

need to convert this SQL2000 DTS validation code to SQL2005 SSIS

Hello,

How do I convert VBSCRIPT code in a DTS package which is used for data validation to SQL 2005 SSIS?

Thanks,

Michael

Michael,

There isn't really a tool to do that for you. Its a manual process I'm afraid.

If you explain what sort of data validation you want to do then you may find people on here will be able to help you achieve the same in SSIS.

-Jamie

|||

Hello,

I have a source table which contains some invalid dates (can be null, letters, etc). I want to check to see if the date is valid. If the date is valid then I want to use it. If the date is not valid then I went to set the destination field to null.

In the past I used vbscript code like


Dim dtStart
Dim dtEnd
Dim dtSource

dtStart = CDate("1/1/1753")
dtEnd = CDate("12/31/9999")

If Not IsNull(DTSSource("MyDate")) Then
If IsDate(DTSSource("MyDate")) Then
dtSource = CDate( DTSSource("MyDate"))

If dtSource >= dtStart and dtSource <= dtEnd Then
DTSDestination("MyDate") = DTSSource("MyDate")
end if
end if
end if
Main = DTSTransformStat_OK

Thanks,

Michael

Need to convert returned values.

I have an application which collects WMI info from servers and stores it in
SQL. The vendor reports for displaying this leave much to be desired. I've
developed numerous replacement reports using SRS, but I'm having trouble
converting the data they collect because of the way it's formatting and
stored....can anyone help?
Sample:
Name[-]\\.\PHYSICALDRIVE0[+]Manufacturer[-]Compaq[+]InterfaceType[-]SCSI[+]MediaType[-]Fixed
hard disk media[+]Model[-]Compaq Disk Array SCSI Disk
Device[+]Status[-]OK[+]Partitions[-]3[+]BytesPerSector[-]512[+]SectorsPerTrack[-]32[+]TracksPerCylinder[-]255[+]TotalSectors[-]53,309,280[+]TotalTracks[-]1,665,915[+]TotalCylinders[-]6,533[+]Size[-]27,294,351,360
I want to drop all of the [-] and [+] and just leave a space between labels
and values.
Any help woul be greatly appreciated.
RCITGUYMaybe in your SQL statment you could try something like this:
SELECT REPLACE(REPLACE(YourColumn,'[+]',' '),'[-]',' ')
"RCITGuy" wrote:
> I have an application which collects WMI info from servers and stores it in
> SQL. The vendor reports for displaying this leave much to be desired. I've
> developed numerous replacement reports using SRS, but I'm having trouble
> converting the data they collect because of the way it's formatting and
> stored....can anyone help?
> Sample:
> Name[-]\\.\PHYSICALDRIVE0[+]Manufacturer[-]Compaq[+]InterfaceType[-]SCSI[+]MediaType[-]Fixed
> hard disk media[+]Model[-]Compaq Disk Array SCSI Disk
> Device[+]Status[-]OK[+]Partitions[-]3[+]BytesPerSector[-]512[+]SectorsPerTrack[-]32[+]TracksPerCylinder[-]255[+]TotalSectors[-]53,309,280[+]TotalTracks[-]1,665,915[+]TotalCylinders[-]6,533[+]Size[-]27,294,351,360
> I want to drop all of the [-] and [+] and just leave a space between labels
> and values.
> Any help woul be greatly appreciated.
> RCITGUY
>|||I have to apologize for sounding stupid...but where should I place this in my
existing SQL select statement? "column holding data is
"WMIConfiguration.Configuration"
___________________________________________________________________
SELECT ComputerGroup.Name, Computer.Name AS Server,
WMIConfiguration.ObjectType, WMIConfiguration.Configuration, Computer.OSVer,
Computer.Address, Computer.PhysicalMem,
Computer.PageSize
FROM Computer INNER JOIN
WMIConfiguration ON Computer.ComputerID =WMIConfiguration.ComputerID INNER JOIN
ComputerGroup ON Computer.GroupID =ComputerGroup.GroupID
WHERE (ComputerGroup.Name = @.Company)
_____________________________________________________________
"Aiwa" wrote:
> Maybe in your SQL statment you could try something like this:
> SELECT REPLACE(REPLACE(YourColumn,'[+]',' '),'[-]',' ')
> "RCITGuy" wrote:
> > I have an application which collects WMI info from servers and stores it in
> > SQL. The vendor reports for displaying this leave much to be desired. I've
> > developed numerous replacement reports using SRS, but I'm having trouble
> > converting the data they collect because of the way it's formatting and
> > stored....can anyone help?
> >
> > Sample:
> > Name[-]\\.\PHYSICALDRIVE0[+]Manufacturer[-]Compaq[+]InterfaceType[-]SCSI[+]MediaType[-]Fixed
> > hard disk media[+]Model[-]Compaq Disk Array SCSI Disk
> > Device[+]Status[-]OK[+]Partitions[-]3[+]BytesPerSector[-]512[+]SectorsPerTrack[-]32[+]TracksPerCylinder[-]255[+]TotalSectors[-]53,309,280[+]TotalTracks[-]1,665,915[+]TotalCylinders[-]6,533[+]Size[-]27,294,351,360
> >
> > I want to drop all of the [-] and [+] and just leave a space between labels
> > and values.
> >
> > Any help woul be greatly appreciated.
> > RCITGUY
> >|||Something like this:
SELECT ComputerGroup.Name,
Computer.Name AS Server,
WMIConfiguration.ObjectType,
REPLACE(REPLACE(WMIConfiguration.Configuration,'[+]','
'),'[-]',' ') AS Configuration ,
Computer.OSVer,
Computer.Address,
Computer.PhysicalMem,
Computer.PageSize
FROM Computer
INNER JOIN WMIConfiguration ON Computer.ComputerID =WMIConfiguration.ComputerID
INNER JOIN ComputerGroup ON Computer.GroupID = ComputerGroup.GroupID
WHERE (ComputerGroup.Name = @.Company)
"RCITGuy" wrote:
> I have to apologize for sounding stupid...but where should I place this in my
> existing SQL select statement? "column holding data is
> "WMIConfiguration.Configuration"
> ___________________________________________________________________
> SELECT ComputerGroup.Name, Computer.Name AS Server,
> WMIConfiguration.ObjectType, WMIConfiguration.Configuration, Computer.OSVer,
> Computer.Address, Computer.PhysicalMem,
> Computer.PageSize
> FROM Computer INNER JOIN
> WMIConfiguration ON Computer.ComputerID => WMIConfiguration.ComputerID INNER JOIN
> ComputerGroup ON Computer.GroupID => ComputerGroup.GroupID
> WHERE (ComputerGroup.Name = @.Company)
> _____________________________________________________________
> "Aiwa" wrote:
> > Maybe in your SQL statment you could try something like this:
> > SELECT REPLACE(REPLACE(YourColumn,'[+]',' '),'[-]',' ')
> >
> > "RCITGuy" wrote:
> >
> > > I have an application which collects WMI info from servers and stores it in
> > > SQL. The vendor reports for displaying this leave much to be desired. I've
> > > developed numerous replacement reports using SRS, but I'm having trouble
> > > converting the data they collect because of the way it's formatting and
> > > stored....can anyone help?
> > >
> > > Sample:
> > > Name[-]\\.\PHYSICALDRIVE0[+]Manufacturer[-]Compaq[+]InterfaceType[-]SCSI[+]MediaType[-]Fixed
> > > hard disk media[+]Model[-]Compaq Disk Array SCSI Disk
> > > Device[+]Status[-]OK[+]Partitions[-]3[+]BytesPerSector[-]512[+]SectorsPerTrack[-]32[+]TracksPerCylinder[-]255[+]TotalSectors[-]53,309,280[+]TotalTracks[-]1,665,915[+]TotalCylinders[-]6,533[+]Size[-]27,294,351,360
> > >
> > > I want to drop all of the [-] and [+] and just leave a space between labels
> > > and values.
> > >
> > > Any help woul be greatly appreciated.
> > > RCITGUY
> > >

Need to convert Date from "YYYY-MM-DD 00:00:00.0000" to "MM/DD/YYYY&qu

Hello, I was asked to run a query to retrieve some data for my boss. The
query works just fine, however, my boss wants to import the data into his
excel spreadsheet, and the date values as displayed in the result set in
query analyzer are in the format "YYYY-MM-DD 00:00:00.0000".
Somehow, I need to be able to convert the date to "MM/DD/YYYY" and trim off
all of the time stamp crap. I tried some CONVERT/CAST functions to no avail
.
This is sort of urgent, PLEASE HELP!!
Thank you...
RGAlso, my date does need the forward slashes too (/) as in "mm/dd/yyyyy".
Thanks.
RG
Robert G wrote:
>Hello, I was asked to run a query to retrieve some data for my boss. The
>query works just fine, however, my boss wants to import the data into his
>excel spreadsheet, and the date values as displayed in the result set in
>query analyzer are in the format "YYYY-MM-DD 00:00:00.0000".
>Somehow, I need to be able to convert the date to "MM/DD/YYYY" and trim off
>all of the time stamp crap. I tried some CONVERT/CAST functions to no avai
l.
>This is sort of urgent, PLEASE HELP!!
>Thank you...
>RG|||If its left in a datetime data type, the time portion will always be
returned. Instead, convert it to a string using something like the
following,
select convert(varchar(10), getdate(), 101)
--Brian
(Please reply to the newsgroups only.)
"Robert G via webservertalk.com" <forum@.webservertalk.com> wrote in message
news:546B8E3963E09@.webservertalk.com...
> Hello, I was asked to run a query to retrieve some data for my boss. The
> query works just fine, however, my boss wants to import the data into his
> excel spreadsheet, and the date values as displayed in the result set in
> query analyzer are in the format "YYYY-MM-DD 00:00:00.0000".
> Somehow, I need to be able to convert the date to "MM/DD/YYYY" and trim
> off
> all of the time stamp crap. I tried some CONVERT/CAST functions to no
> avail.
> This is sort of urgent, PLEASE HELP!!
> Thank you...
> RG|||SQL Server does not have a "date only" data type, so you will need to jump
through some hoops...
Since your boss is importing the data into Excel, my first recommendation
would be to leave the data as it is, and just format it appropriately in
Excel. Excel can easily suppress the display of the time values, and it will
properly recognize the values as date values.
If that is not an option, you could try a kludge such as "SELECT
CONVERT(CHAR(8), DateColumn, 112), <other columns here> FROM UnknownTable",
which will output a character column formatted as 'YYYYMMDD'. Depending on
how you are making this output available to Excel, Excel may or may not
determine that this is a Date column, and may not provide proper sorting
functionality.
"Robert G via webservertalk.com" <forum@.webservertalk.com> wrote in message
news:546B8E3963E09@.webservertalk.com...
> Hello, I was asked to run a query to retrieve some data for my boss. The
> query works just fine, however, my boss wants to import the data into his
> excel spreadsheet, and the date values as displayed in the result set in
> query analyzer are in the format "YYYY-MM-DD 00:00:00.0000".
> Somehow, I need to be able to convert the date to "MM/DD/YYYY" and trim
> off
> all of the time stamp crap. I tried some CONVERT/CAST functions to no
> avail.
> This is sort of urgent, PLEASE HELP!!
> Thank you...
> RG|||References: <546B8E3963E09@.webservertalk.com>
In-Reply-To: <546B8E3963E09@.webservertalk.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <#Wf$YLkuFHA.860@.TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.sqlserver.programming
NNTP-Posting-Host: 208.13.225.3
Path: TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Lines: 1
Xref: TK2MSFTNGP08.phx.gbl microsoft.public.sqlserver.programming:552942
in addition to the other comments - you could simply change the boss's
spreadsheet column to display date format. :)
Robert G via webservertalk.com wrote:

>Hello, I was asked to run a query to retrieve some data for my boss. The
>query works just fine, however, my boss wants to import the data into his
>excel spreadsheet, and the date values as displayed in the result set in
>query analyzer are in the format "YYYY-MM-DD 00:00:00.0000".
>Somehow, I need to be able to convert the date to "MM/DD/YYYY" and trim off
>all of the time stamp crap. I tried some CONVERT/CAST functions to no avai
l.
>This is sort of urgent, PLEASE HELP!!
>Thank you...
>RG
>|||Hell yes, thanks Brian!!! That worked like a freakin charm !! I did the
following:
convert(varchar(10), [MyDateField], 101)
I'd really like to thank everyone else who responded as well !!! I hope I
can return the favor some day.
RG
Brian Lawton wrote:
>If its left in a datetime data type, the time portion will always be
>returned. Instead, convert it to a string using something like the
>following,
>select convert(varchar(10), getdate(), 101)
>
>[quoted text clipped - 10 lines]|||I know what it is like to have a boss who is a total idiot, but you
might wantot get him/her a copy of ISO-8601 and ask why he is smarter
than the entire world. I would love to hear his/her reply :)
The kludge for the moron is a CONVERT() in a VIEW.|||Hey thanks for your input. That does what you said it would, but excel
doesn't recognize it as a date format. Also, I could've parsed it in the
query and eventually ended up with what I needed, but it would've required a
lot more work than Brian's solution - which took like two seconds.
But thanks so much, I still learned from your response.
RG
Jeremy Williams wrote:
>SQL Server does not have a "date only" data type, so you will need to jump
>through some hoops...
>Since your boss is importing the data into Excel, my first recommendation
>would be to leave the data as it is, and just format it appropriately in
>Excel. Excel can easily suppress the display of the time values, and it wil
l
>properly recognize the values as date values.
>If that is not an option, you could try a kludge such as "SELECT
>CONVERT(CHAR(8), DateColumn, 112), <other columns here> FROM UnknownTable",
>which will output a character column formatted as 'YYYYMMDD'. Depending on
>how you are making this output available to Excel, Excel may or may not
>determine that this is a Date column, and may not provide proper sorting
>functionality.
>
>[quoted text clipped - 10 lines]
Message posted via webservertalk.com
http://www.webservertalk.com/Uwe/Forum...amming/200509/1

Need to convert Date from "YYYY-MM-DD 00:00:00.0000" to "MM/DD

select substring(CONVERT(CHAR(8), date, 112), 5,2) + '/'
+ substring(CONVERT(CHAR(8), date, 112), 7,2) + '/'
+ substring(CONVERT(CHAR(8), date, 112), 1,4)
from table
Archer
"Trey Walpole" wrote:

> in addition to the other comments - you could simply change the boss's
> spreadsheet column to display date format. :)
> Robert G via webservertalk.com wrote:
>
>or just
select convert(varchar,date,101)
from table
:)
bagman3rd wrote:
>select substring(CONVERT(CHAR(8), date, 112), 5,2) + '/'
>+ substring(CONVERT(CHAR(8), date, 112), 7,2) + '/'
>+ substring(CONVERT(CHAR(8), date, 112), 1,4)
>from table
>Archer
>"Trey Walpole" wrote:
>
>

Need to convert cursor

I am new to SQL and have created a stored procedure for a .net web
application. Unfortunately I had to use a cursor in the stored
procedure, so it is taking several minutes to execute because it has to
read through about 15,000 records. There must be another way to do
what I'm trying to do without a cursor. I've tried temp tables and
case statements, but I can't seem to get them to work. I've been
trying to figure this out for over a week and I am just running into a
wall. Some expert advise would be much appreciated. My code is below.
Thank you in advance.

--Insert records into first temp table
DECLARE @.tempA TABLE
(
lnkey varchar(10),
AuditorIDvarchar(7)
)

INSERT INTO @.tempA

SELECT
LNKEY
,AuditorID

FROM
dbo.tblALPSLoans
WHERE AuditDate BETWEEN @.BegDate AND @.EndDate --parameters from my
application
AND AuditorID IN (SELECT LANID FROM dbo.tblEmployees WHERE ACTIONTYPE =
'ADDED')
AND AuditType = @.AuditType --parameter from my application

--Insert percentage value of Pre-Funding completes for each auditor
into temp table B
DECLARE @.tempB TABLE
(
LnkeyCount int,
AuditorIDvarchar(7)
)

INSERT INTO @.tempB

SELECT
ROUND(COUNT(LNKEY) * @.Percent/100, 0) AS 'LnkeyCount'
,AuditorID
FROM dbo.tblALPSLoans
WHERE AuditDate BETWEEN @.BegDate AND @.EndDate
AND AuditorID IN (SELECT LANID FROM dbo.tblEmployees WHERE ACTIONTYPE =
'ADDED')
GROUP BY AuditorID

/*Create cursor to loop through records and add a loan number to
tblinjectloans if the number of loans in tblinjectloans for each
auditor is less than the percentage value for each auditor from
@.tempB*/

DECLARE @.lnkey varchar(10)
DECLARE @.AuditorID varchar(7)
DECLARE @.var1int
DECLARE @.var2int
DECLARE @.sqlvarchar(4000)

DECLARE c1 CURSOR FOR
SELECT lnkey, auditorid
FROM @.TempA

OPEN c1

FETCH NEXT FROM c1
INTO @.LNKEY, @.AuditorID

WHILE @.@.FETCH_STATUS = 0
BEGIN

Select @.var1 = COUNT(Lnkey) from dbo.tblInjectLoans where
AuditorID=@.AuditorID
Select @.var2 = LnkeyCount from @.tempB where AuditorID=@.AuditorID
IF @.var1 < @.var2
Insert into dbo.tblInjectLoans
(lnkey, AuditorID)
Values (@.LNKEY, @.AuditorID)

FETCH NEXT FROM c1
INTO @.LNKEY, @.AuditorID

END

CLOSE c1
DEALLOCATE c1Patti wrote:

Quote:

Originally Posted by

I am new to SQL and have created a stored procedure for a .net web
application. Unfortunately I had to use a cursor in the stored
procedure, so it is taking several minutes to execute because it has to
read through about 15,000 records. There must be another way to do
what I'm trying to do without a cursor. I've tried temp tables and
case statements, but I can't seem to get them to work. I've been
trying to figure this out for over a week and I am just running into a
wall. Some expert advise would be much appreciated. My code is below.
Thank you in advance.
>
>
--Insert records into first temp table
DECLARE @.tempA TABLE
(
lnkey varchar(10),
AuditorIDvarchar(7)
)
>
INSERT INTO @.tempA
>
SELECT
LNKEY
,AuditorID
>
FROM
dbo.tblALPSLoans
WHERE AuditDate BETWEEN @.BegDate AND @.EndDate --parameters from my
application
AND AuditorID IN (SELECT LANID FROM dbo.tblEmployees WHERE ACTIONTYPE =
'ADDED')
AND AuditType = @.AuditType --parameter from my application
>
>
--Insert percentage value of Pre-Funding completes for each auditor
into temp table B
DECLARE @.tempB TABLE
(
LnkeyCount int,
AuditorIDvarchar(7)
)
>
INSERT INTO @.tempB
>
SELECT
ROUND(COUNT(LNKEY) * @.Percent/100, 0) AS 'LnkeyCount'
,AuditorID
FROM dbo.tblALPSLoans
WHERE AuditDate BETWEEN @.BegDate AND @.EndDate
AND AuditorID IN (SELECT LANID FROM dbo.tblEmployees WHERE ACTIONTYPE =
'ADDED')
GROUP BY AuditorID
>
>
>
/*Create cursor to loop through records and add a loan number to
tblinjectloans if the number of loans in tblinjectloans for each
auditor is less than the percentage value for each auditor from
@.tempB*/
>
DECLARE @.lnkey varchar(10)
DECLARE @.AuditorID varchar(7)
DECLARE @.var1int
DECLARE @.var2int
DECLARE @.sqlvarchar(4000)
>
>
DECLARE c1 CURSOR FOR
SELECT lnkey, auditorid
FROM @.TempA
>
OPEN c1
>
FETCH NEXT FROM c1
INTO @.LNKEY, @.AuditorID
>
WHILE @.@.FETCH_STATUS = 0
BEGIN
>
Select @.var1 = COUNT(Lnkey) from dbo.tblInjectLoans where
AuditorID=@.AuditorID
Select @.var2 = LnkeyCount from @.tempB where AuditorID=@.AuditorID
IF @.var1 < @.var2
Insert into dbo.tblInjectLoans
(lnkey, AuditorID)
Values (@.LNKEY, @.AuditorID)
>
>
FETCH NEXT FROM c1
INTO @.LNKEY, @.AuditorID
>
END
>
CLOSE c1
DEALLOCATE c1


Untested:

insert into tblInjectLoans (lnkey, AuditorID)
select lnkey, AuditorID
from tblALPSLoans al
where AuditDate between @.BegDate and @.EndDate
and AuditorID in (
select lanid
from tblEmployees
where actiontype = 'ADDED'
)
and AuditType = @.AuditType
and (select count(lnkey)
from tblInjectLoans il
where il.AuditorID = al.AuditorID
)
< (select round(count(lnkey) * @.Percent/100, 0)
from tblALPSLoans al2
where al2.AuditDate between @.BegDate and @.EndDate
and al2.AuditorID = al.AuditorID
)|||This was a great suggestion, thank you. I've actually been playing
with the code because right now it inserts every record from the
tblALPSLoans table into the tblinjectloans table for each auditor. But
I need it to insert just enough records for each auditor until the
percentage number for that auditor is met. So, for example, if auditor
A has 1 record in the tblInjectLoans table and his percentage number
(lnkeycount from @.tempb from my original code) is 3, then I need to
insert only 2 more records from the tblALPSLoans table into
tblInjectLoans. I was playing with Top N, but that isn't working for
me. Hopefully, this makes sense. Any ideas would be much appreciated.

Ed Murphy wrote:

Quote:

Originally Posted by

Patti wrote:
>

Quote:

Originally Posted by

I am new to SQL and have created a stored procedure for a .net web
application. Unfortunately I had to use a cursor in the stored
procedure, so it is taking several minutes to execute because it has to
read through about 15,000 records. There must be another way to do
what I'm trying to do without a cursor. I've tried temp tables and
case statements, but I can't seem to get them to work. I've been
trying to figure this out for over a week and I am just running into a
wall. Some expert advise would be much appreciated. My code is below.
Thank you in advance.

--Insert records into first temp table
DECLARE @.tempA TABLE
(
lnkey varchar(10),
AuditorIDvarchar(7)
)

INSERT INTO @.tempA

SELECT
LNKEY
,AuditorID

FROM
dbo.tblALPSLoans
WHERE AuditDate BETWEEN @.BegDate AND @.EndDate --parameters from my
application
AND AuditorID IN (SELECT LANID FROM dbo.tblEmployees WHERE ACTIONTYPE =
'ADDED')
AND AuditType = @.AuditType --parameter from my application

--Insert percentage value of Pre-Funding completes for each auditor
into temp table B
DECLARE @.tempB TABLE
(
LnkeyCount int,
AuditorIDvarchar(7)
)

INSERT INTO @.tempB

SELECT
ROUND(COUNT(LNKEY) * @.Percent/100, 0) AS 'LnkeyCount'
,AuditorID
FROM dbo.tblALPSLoans
WHERE AuditDate BETWEEN @.BegDate AND @.EndDate
AND AuditorID IN (SELECT LANID FROM dbo.tblEmployees WHERE ACTIONTYPE =
'ADDED')
GROUP BY AuditorID

/*Create cursor to loop through records and add a loan number to
tblinjectloans if the number of loans in tblinjectloans for each
auditor is less than the percentage value for each auditor from
@.tempB*/

DECLARE @.lnkey varchar(10)
DECLARE @.AuditorID varchar(7)
DECLARE @.var1int
DECLARE @.var2int
DECLARE @.sqlvarchar(4000)

DECLARE c1 CURSOR FOR
SELECT lnkey, auditorid
FROM @.TempA

OPEN c1

FETCH NEXT FROM c1
INTO @.LNKEY, @.AuditorID

WHILE @.@.FETCH_STATUS = 0
BEGIN

Select @.var1 = COUNT(Lnkey) from dbo.tblInjectLoans where
AuditorID=@.AuditorID
Select @.var2 = LnkeyCount from @.tempB where AuditorID=@.AuditorID
IF @.var1 < @.var2
Insert into dbo.tblInjectLoans
(lnkey, AuditorID)
Values (@.LNKEY, @.AuditorID)

FETCH NEXT FROM c1
INTO @.LNKEY, @.AuditorID

END

CLOSE c1
DEALLOCATE c1


>
Untested:
>
insert into tblInjectLoans (lnkey, AuditorID)
select lnkey, AuditorID
from tblALPSLoans al
where AuditDate between @.BegDate and @.EndDate
and AuditorID in (
select lanid
from tblEmployees
where actiontype = 'ADDED'
)
and AuditType = @.AuditType
and (select count(lnkey)
from tblInjectLoans il
where il.AuditorID = al.AuditorID
)
< (select round(count(lnkey) * @.Percent/100, 0)
from tblALPSLoans al2
where al2.AuditDate between @.BegDate and @.EndDate
and al2.AuditorID = al.AuditorID
)

|||Patti (pdavis269@.worldsavings.com) writes:

Quote:

Originally Posted by

This was a great suggestion, thank you. I've actually been playing
with the code because right now it inserts every record from the
tblALPSLoans table into the tblinjectloans table for each auditor. But
I need it to insert just enough records for each auditor until the
percentage number for that auditor is met. So, for example, if auditor
A has 1 record in the tblInjectLoans table and his percentage number
(lnkeycount from @.tempb from my original code) is 3, then I need to
insert only 2 more records from the tblALPSLoans table into
tblInjectLoans. I was playing with Top N, but that isn't working for
me. Hopefully, this makes sense. Any ideas would be much appreciated.


So does the original code you posted produce the correct result or
not? This is not clear to me.

A good idea for this type of questions, is that you post:

o CREATE TABLE statements for your tables, preferrably simplified to
the pertinent columns.
o INSERT statement with sample data.
o The desired result given the sample.

This make it easy to copy and paste and develop a tested solution. Also
the test data helps to clarify the verbal resitriction.

Note that the amount of sample data can be fairly small, but it should
be big enough to cover important cases.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||My original code does produce the correct result. Below I have
simplified my original code and have given some sample data. I hope
this helps clarifies what I am looking for. Thank you in advance.

/*This is how the tblInjectLoans table
looks like before I start my cursor.*/

LNKEY AuditorID
000001 lpAAAAA
000002 lpBBBBB
000003 lpCCCCC

/*I then need to find 3 percent of completed loans for each auditor and
insert it into
a temp table*/

INSERT INTO @.tempB

SELECT
ROUND(COUNT(LNKEY) * 3/100, 0) AS 'LnkeyCount'
,AuditorID
FROM dbo.tblALPSLoans
GROUP BY AuditorID

/*Results of @.TempB insert
AuditorID LnkeyCount
lpAAAAA 3
lpBBBBB 2
lpCCCCC 1
*/

/*Create cursor to loop through records and add a loan number to
tblinjectloans table if the number of loans in tblinjectloans for each

auditor is less than the LnkeyCount for each auditor from
@.tempB*/

DECLARE @.lnkey varchar(10)
DECLARE @.AuditorID varchar(7)
DECLARE @.var1 int
DECLARE @.var2 int
DECLARE @.sql varchar(4000)

DECLARE c1 CURSOR FOR
SELECT lnkey, auditorid
FROM @.TempA

OPEN c1

FETCH NEXT FROM c1
INTO @.LNKEY, @.AuditorID

WHILE @.@.FETCH_STATUS = 0
BEGIN

Select @.var1 = COUNT(Lnkey) from dbo.tblInjectLoans where
AuditorID=@.AuditorID
Select @.var2 = LnkeyCount from @.tempB where
AuditorID=@.AuditorID
IF @.var1 < @.var2
Insert into dbo.tblInjectLoans
(lnkey, AuditorID)
Values (@.LNKEY, @.AuditorID)

FETCH NEXT FROM c1
INTO @.LNKEY, @.AuditorID

END

CLOSE c1
DEALLOCATE c1

/*Desired results of tblInjectLoans when cursor is done
LNKEY AuditorID
00001 lpAAAAA
00005 lpAAAAA
00007 lpAAAAA
00002 lpBBBBB
00008 lpBBBBB
00003 lpCCCCC
*/

As you can see each auditor's count of loans is equal to the number of
LNKEYCount from @.TempB. This is my ultimate desired results. I need
loans added to the tblInjectLoans for each auditor until the total for
that auditor reaches their LNKEYCount from @.tempB. My original code
does produce these results. It just takes a long time to run.

Erland Sommarskog wrote:

Quote:

Originally Posted by

Patti (pdavis269@.worldsavings.com) writes:

Quote:

Originally Posted by

This was a great suggestion, thank you. I've actually been playing
with the code because right now it inserts every record from the
tblALPSLoans table into the tblinjectloans table for each auditor. But
I need it to insert just enough records for each auditor until the
percentage number for that auditor is met. So, for example, if auditor
A has 1 record in the tblInjectLoans table and his percentage number
(lnkeycount from @.tempb from my original code) is 3, then I need to
insert only 2 more records from the tblALPSLoans table into
tblInjectLoans. I was playing with Top N, but that isn't working for
me. Hopefully, this makes sense. Any ideas would be much appreciated.


>
So does the original code you posted produce the correct result or
not? This is not clear to me.
>
A good idea for this type of questions, is that you post:
>
o CREATE TABLE statements for your tables, preferrably simplified to
the pertinent columns.
o INSERT statement with sample data.
o The desired result given the sample.
>
This make it easy to copy and paste and develop a tested solution. Also
the test data helps to clarify the verbal resitriction.
>
Note that the amount of sample data can be fairly small, but it should
be big enough to cover important cases.
>
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

|||Patti (pdavis269@.worldsavings.com) writes:

Quote:

Originally Posted by

My original code does produce the correct result. Below I have
simplified my original code and have given some sample data. I hope
this helps clarifies what I am looking for. Thank you in advance.


You did not say which version of SQL Server you are using. The solution
below works on SQL 2000, but on SQL 2005 it should be possible to
all in one query.

First, add this column to @.TempA:

rowno int IDENTITY

No you can insert all rows at once with:

INSERT dbo.tblInjectLoans (lnkey, AuditorID)
SELECT a.lnkey, a.auditorid
FROM @.TempA a
JOIN @.TempB b ON a.AuthorID = b.AuthorIS
WHERE b.lnkey >
a.rowno + (SELECT COUNT(il.Lnkey)
FROM tblInjectLoans il
WHERE il.AuditorID = a.AuditorID)

Since you did not include a repro script (i.e. the CREATE TABLE and
INSERT statements I was asking for) this untest.

Note that the code as you have written is not deterministic in which
loans that goes to which auditor, but nor is it anything that can be
called random.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||I apologize if I sound naive, but I am unfamiliar with what a repro
script is. I am hoping this is what you need:

tblInjectLoans:
CREATE TABLE [tblInjectLoans] (
[lnkey] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[AuditorID] [varchar] (7) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[QualityAuditorID] [varchar] (7) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[ID] [int] IDENTITY (1, 1) NOT NULL ,
CONSTRAINT [PK_tblInjectLoans] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY]
GO

tblALPSLoans:
CREATE TABLE [tblALPSLoans] (
[IDX] [int] IDENTITY (1, 1) NOT NULL ,
[LNKEY] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[AuditorID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[AuditDate] [datetime] NULL ,
[AuditType] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
CONSTRAINT [PK_tblALPSLoans] PRIMARY KEY CLUSTERED
(
[IDX]
) ON [PRIMARY]
) ON [PRIMARY]
GO

I tried your suggestion and it is giving me all loans from temp table A
for each auditor where the count of loans from tblInjectLoans is
greater than the lnkeycount from temp table B. I do not want all loans
from temp table A, I want enough loans inserted until the lnkeycount
for each auditor is reached. Ex.

lnkeycount for Auditor lpAAAA = 3
lnkeycount for Auditor lpBBBB = 2
lnkeycount for Auditor lpCCCC = 1

Results:

LNKEY AuditorID
00001 lpAAAAA
00005 lpAAAAA
00007 lpAAAAA
00002 lpBBBBB
00008 lpBBBBB
00003 lpCCCCC

Thanks in advance!

Erland Sommarskog wrote:

Quote:

Originally Posted by

Patti (pdavis269@.worldsavings.com) writes:

Quote:

Originally Posted by

My original code does produce the correct result. Below I have
simplified my original code and have given some sample data. I hope
this helps clarifies what I am looking for. Thank you in advance.


>
You did not say which version of SQL Server you are using. The solution
below works on SQL 2000, but on SQL 2005 it should be possible to
all in one query.
>
First, add this column to @.TempA:
>
rowno int IDENTITY
>
No you can insert all rows at once with:
>
INSERT dbo.tblInjectLoans (lnkey, AuditorID)
SELECT a.lnkey, a.auditorid
FROM @.TempA a
JOIN @.TempB b ON a.AuthorID = b.AuthorIS
WHERE b.lnkey >
a.rowno + (SELECT COUNT(il.Lnkey)
FROM tblInjectLoans il
WHERE il.AuditorID = a.AuditorID)
>
>
Since you did not include a repro script (i.e. the CREATE TABLE and
INSERT statements I was asking for) this untest.
>
Note that the code as you have written is not deterministic in which
loans that goes to which auditor, but nor is it anything that can be
called random.
>
>
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

|||Patti (pdavis269@.worldsavings.com) writes:

Quote:

Originally Posted by

I apologize if I sound naive, but I am unfamiliar with what a repro
script is. I am hoping this is what you need:


A repro script is something that reproduces something. The term is maybe
most commonly used in conjunction with bugs. That is, if you think that
you have found a bug, I would ask you for away to reproduce the problem.

In this case, I suggested a couple of posts back that you should post
CREATE TABLE statements for your tables and INSERT statements with
sample data, as well as the desired result give the sample. Calling
this a repro is maybe inaccurate. It is really a unit test, at least
if the sample data is well chosen.

You posted the table this time, but not the sample data. So I am sorry,
but I will not take any more stab at your problem. I would have to
guess too much. I'm sorry that the solution in my previous post did
not work. Maybe I misunderstood the requirements, maybe I made a
mistake when I composed the solution. Without test data, and without
the expected result from the test data, it is very difficult to write
a usable solution.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Patti (pdavis269@.worldsavings.com) writes:

Quote:

Originally Posted by

I apologize if I sound naive, but I am unfamiliar with what a repro
script is. I am hoping this is what you need:


By the way, you still have not said which version of SQL Server you are
using.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx