Showing posts with label row. Show all posts
Showing posts with label row. Show all posts

Saturday, February 25, 2012

articles default

hi all, I was trying to set the articles to "delete data in the existing table that matches the row filter" in the publications "article>articles>table articles>snapshot" of the publication but everytime i reopen that property tab the publication restore to the default setting of 
"drop exisiting table and recreate it" 
i"m using sql server 2000. snapshot replication
-- thanks, joey
You can make use of dynamic snapshot to filter out the data.

article row filter - 2 parameters

hello,

i need to filter an article based on a user-supplied datetime filter (the datetime parameter is specified by the subscriber just before replication). at the same time i need to filter again by user (different subscribers get different rows).

i already did the user-based filter using HOST_NAME( ). but the difficulty here (al least i think so) lies in passing 2 parameters to the filter. i cannot rely on using SUSER_SNAME to pass the user filter, because no one will want to create 500 user accounts. so i guess the only solution here is to pass both parameters using only HOST_NAME( ) and then write 2 splitting functions which uses HOST_NAME( ) as its parameter. am i right ?

publisher/distributor is sql server 2005, all subscribers use sql mobile.

TIA, kamil nowicki

Using datetime would not be recommended since it is not deterministic.

For eg:

lets say you have a filter to get rows being touched only in the last 7 days.

Initially you get all rows.

After 7 days having not touched any rows, you would expect the merge agent deletes the 7 rows which will not be the case.

I would advise you to use SUSER_SNAME() or HOST_NAME() to get specific rows and in addition use another column 'status' or something that you can set/reset according to your business needs.

|||

thanks for replying.

i think that i have to use a datetime filter because the parameter to this filter has to be dynamic (worst case scenario: each subscriber uses different filter parameter for each of his replication sessions). is there another way to accomplish this ?

also, is there a way to store something in SUSER_SNAME() like using SqlCeReplication.HostName to store something into HOSTNAME() ?

|||

If each session of the subscriber uses a different filter, you will get an error with mismatched partitions. You would need to reinitialize the subscriber in that case. Are you ready to reinitialize the subscribers for every sync?

But note that as I mentioned previously, you will not be able to rely on datetime filter. Use a status column or something like that and update this column when you want rows to be in partition or out of partition.

|||

>> Use a status column or something like that and update this column when you want rows to be in partition or out of partition.

but that would mean that i have to use a "fixed filter" (same "replicate from ..." date for every subscriber), wouldn't it ?

|||How about: login=SUSER_SNAME and status='Y'|||

We have a best practice article for time-based filtering, you may want to reference it, it's what Mahesh is talking about:

Best Practices for Time-Based Row Filters

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

|||

and how does that solve my scenario ? i want each subscriber to be able to choose a date ( "replicate from..." ) before each of his replication sessions. SP on the server will not know those dates when executed, so how am i supposed to update the "status" column ?

thanks for the link, i have read that before starting the thread.

|||

Are you saying that every time the subscriber syncs, it sends a new date and expects only releant rows? You cannot achieve this using the non-deterministic filter functions. If you are ready to reinitialize your subscriptions every time you sync, you may do that. Do a reinit on the publisher/subscriber, then send in the appropriate date as the hostname to get the relevant rows. However you wont be able to upload in this session because your filters may not match data that you want to upload.

|||

i took a different approach and now everything is working as it should. i wrote a SP on the backend server which updates every row in the filtered article for a given user (SP is parametrized with @.user nvarchar and @.filter datetime), changing rep_status tinyint column. the SP is called from subscriber on the distributor just before each replication session, so now the SP has all the info to update the filtered article (@.user and @.filter). article is filtered by rep_status.

the drawback is that the backend has to be put out of LAN to the internet (public IP), but later i will write a WebService so that all the data will pass through IIS and then the backend will be again NATed.

edit: and of course this works without subscription reinitialization :)

Friday, February 24, 2012

Array in TSQL

Hi all,

I have data like this :

POHDR;JAKARTA;St.1
DTL;1. ;00248337;8996006855701 ;083;041;002; 7,812.50; 312,500.00; 284,091.00; 8,875.00

first row is the PO header and the second is the detail. This data was collected using Export Import Wizard from flatfile and put it in one column. I want to split the header and the detail into different table and map each column separated by ; to a proper field. For this work I should check every column separated by ; with CHARINDEX function but I have to write the TSQL as much as the count of ;. It would be better if we can use array to simplify the code.

Can we use array in Transact SQL ? since I have no clue referring to SQLBOL. Thanks in advance.

Best regards,

Hery

Hi Hery,

You can add identity column to the table so you can asume that the ids with odd numbers (i.e. 1, 3, 5 ..) as PO Header and the Ids with Even Numbers as Details..

Regarding Arrays.. I am sorry there is no such concept.. but you can go through following link to get it work..

http://www.sommarskog.se/arrays-in-sql.html

Hope this will help you..

|||Hi SajidAttar,

Thanks for the article, it helps me much.

Best regards,

Hery|||

Hi..

Glad to help.. and to be honest.. effort goes to the author..Smile

All the best.

Array in TSQL

Hi all,

I have data like this :

POHDR;JAKARTA;St.1
DTL;1. ;00248337;8996006855701 ;083;041;002; 7,812.50; 312,500.00; 284,091.00; 8,875.00

first row is the PO header and the second is the detail. This data was collected using Export Import Wizard from flatfile and put it in one column. I want to split the header and the detail into different table and map each column separated by ; to a proper field. For this work I should check every column separated by ; with CHARINDEX function but I have to write the TSQL as much as the count of ;. It would be better if we can use array to simplify the code.

Can we use array in Transact SQL ? since I have no clue referring to SQLBOL. Thanks in advance.

Best regards,

Hery

Hi Hery,

You can add identity column to the table so you can asume that the ids with odd numbers (i.e. 1, 3, 5 ..) as PO Header and the Ids with Even Numbers as Details..

Regarding Arrays.. I am sorry there is no such concept.. but you can go through following link to get it work..

http://www.sommarskog.se/arrays-in-sql.html

Hope this will help you..

|||Hi SajidAttar,

Thanks for the article, it helps me much.

Best regards,

Hery|||

Hi..

Glad to help.. and to be honest.. effort goes to the author..Smile

All the best.

Sunday, February 19, 2012

Array in TSQL

Hi all,

I have data like this :

POHDR;JAKARTA;St.1
DTL;1. ;00248337;8996006855701 ;083;041;002; 7,812.50; 312,500.00; 284,091.00; 8,875.00

first row is the PO header and the second is the detail. This data was collected using Export Import Wizard from flatfile and put it in one column. I want to split the header and the detail into different table and map each column separated by ; to a proper field. For this work I should check every column separated by ; with CHARINDEX function but I have to write the TSQL as much as the count of ;. It would be better if we can use array to simplify the code.

Can we use array in Transact SQL ? since I have no clue referring to SQLBOL. Thanks in advance.

Best regards,

Hery

Hi Hery,

You can add identity column to the table so you can asume that the ids with odd numbers (i.e. 1, 3, 5 ..) as PO Header and the Ids with Even Numbers as Details..

Regarding Arrays.. I am sorry there is no such concept.. but you can go through following link to get it work..

http://www.sommarskog.se/arrays-in-sql.html

Hope this will help you..

|||Hi SajidAttar,

Thanks for the article, it helps me much.

Best regards,

Hery|||

Hi..

Glad to help.. and to be honest.. effort goes to the author..Smile

All the best.

Array

We are creating a report that we view detail records and find a row in the
list of records and want to grab one of the fields associated with that
record.
Example:
I have a loan number and principle balance.
I count the number of loans for a borrower.
Here is the data:
LN NUM Prin
1 5.00
2 10.00
3 15.00
The middle record is the one I want to use. But what I want as well is the
prin amount. How do I tell a function to look at the prin amount instead of
the ln num field?Hi Susan,
I've run into a similar issue. Were you able to resolve your issue? If so
please tell.
THanks,
"Susan" wrote:
> We are creating a report that we view detail records and find a row in the
> list of records and want to grab one of the fields associated with that
> record.
> Example:
> I have a loan number and principle balance.
> I count the number of loans for a borrower.
> Here is the data:
> LN NUM Prin
> 1 5.00
> 2 10.00
> 3 15.00
> The middle record is the one I want to use. But what I want as well is the
> prin amount. How do I tell a function to look at the prin amount instead of
> the ln num field?
>|||No I actually was looking for a way to calculate the median. I had to write
the report in Crystal.
"DigitalVixen" wrote:
> Hi Susan,
> I've run into a similar issue. Were you able to resolve your issue? If so
> please tell.
> THanks,
>
> "Susan" wrote:
> > We are creating a report that we view detail records and find a row in the
> > list of records and want to grab one of the fields associated with that
> > record.
> > Example:
> >
> > I have a loan number and principle balance.
> > I count the number of loans for a borrower.
> > Here is the data:
> >
> > LN NUM Prin
> > 1 5.00
> > 2 10.00
> > 3 15.00
> >
> > The middle record is the one I want to use. But what I want as well is the
> > prin amount. How do I tell a function to look at the prin amount instead of
> > the ln num field?
> >

Arranging data on multiple rows into a sigle row (converting rows into columns)

Hello,

I have a survey (30 questions) application in a SQL server db. The application uses several relational tables. The results are arranged so that each answer is on a seperate row:

user1 answer1
user1 answer2
user1 answer3
user2 answer1
user2 answer2
user2 answer3

For statistical analysis I need to transfer the results to an Excel spreadsheet (for later use in SPSS). In the spreadsheet I need the results to appear so thateach user will be on a single row with all of that user's answers on that single row (A column for each answer):

user1 answer1 answer2 answer3
user2 answer1 answer2 answer3

How can this be done? How can all answers of a user appear on a single row

Thanx,
Danny.

sql server 2005 or 2000?

In sql server 2005, I believe the answer is with the new pivot or unpivot commands. In 2000, it gets much trickier.

Of course, I think excel can do it's own pivoting as well.

Thursday, February 16, 2012

Arithmetic overflow error converting expression to data type datetime.

Ya ? am taking this error message in Asp.Net and i am not inserting a new row my database.

i have a databese and my fields

EmailID-->int

EmailAdress-->varchar(100)

DateTime-->datetime

IPAdress-->char(15)

Please help me,thanks

Most likely a disparity between the application date format and the date format SQL Server 'expects'. (Application passing the date parameter in the form of dd/mm/yyyy, and SQL Server accepting that as mm/dd/yyyy -and the ensuing date is invalid.

Have the application pass the date parameter in the ISO form of: yyyy/mm/dd OR yyyymmdd.

Arithmetic overflow error

Hi,

After 6 months running with the datatype decimal(15,2), every time that I want to update a row, the following message is displayed,

Microsoft SQL Server:8115[Microsoft][ODBC SQL Server Driver][SQL
Server]Arithmetic overflow error converting float to data type
numeric

and the decimal data is shift to left, like this sample:

41.61 >> 4161.00
62.30 >> 623.00

Anyone can help?

tksHave you run a dbcc check on the table/database?

Try doing a compare
select * from tbl where fld = 62.3 to find if it is a presentation or data problem (probably it is the data)

What happens if you do
select convert(decimal(15,2),62.3)