Showing posts with label rep. Show all posts
Showing posts with label rep. Show all posts

Sunday, March 25, 2012

Adding A default value in a column in a declare statment

Hi Can anybody help me.

I have this querey at the minute but when I attempt to put the default value of IND in the Sales Rep Code field I get an error Invalid column name, if I try and put 'IND' AS [Sales Rep Code] I get an incorrect syntax error.

DECLARE @.Query nVarchar(1000)
SET @.Query = N'SELECT NULL AS [GEO UNIT], NULL AS [PMC Invoice Date], IND AS [Sales Rep Code] FROM '+ 'Test' + RIGHT(DATEPART(yy, GETDATE()), 2) + '_' + CASE WHEN DATEPART(m, GETDATE()) IN ('11', '12', '1')
THEN 'Q1' ELSE CASE WHEN DATEPART(m, GETDATE()) IN ('2', '3', '4') THEN 'Q2' ELSE CASE WHEN DATEPART(m, GETDATE()) IN ('5', '6', '7')
THEN 'Q3' ELSE CASE WHEN DATEPART(m, GETDATE()) IN ('8', '9', '10') THEN 'Q4' END END END END + '.dbo.all_data' EXECUTE sp_executesql @.Query, N'@.level tinyint', @.level = 35

Can anybody please help on this.

ThanksHi Can anybody help me.

I have this querey at the minute but when I attempt to put the default value of IND in the Sales Rep Code field I get an error Invalid column name, if I try and put 'IND' AS [Sales Rep Code] I get an incorrect syntax error.

DECLARE @.Query nVarchar(1000)
SET @.Query = N'SELECT NULL AS [GEO UNIT], NULL AS [PMC Invoice Date], IND AS [Sales Rep Code] FROM '+ 'Test' + RIGHT(DATEPART(yy, GETDATE()), 2) + '_' + CASE WHEN DATEPART(m, GETDATE()) IN ('11', '12', '1')
THEN 'Q1' ELSE CASE WHEN DATEPART(m, GETDATE()) IN ('2', '3', '4') THEN 'Q2' ELSE CASE WHEN DATEPART(m, GETDATE()) IN ('5', '6', '7')
THEN 'Q3' ELSE CASE WHEN DATEPART(m, GETDATE()) IN ('8', '9', '10') THEN 'Q4' END END END END + '.dbo.all_data' EXECUTE sp_executesql @.Query, N'@.level tinyint', @.level = 35

Can anybody please help on this.

Thanks

would help us if u could post the ddl for the table|||what is the dataytpe of [Sales Rep Code]?
Off the cuff, it looks like your IND value is supposed to be a string.
Your example would be OK if you use 'IND' as [Sales Rep Code] - with the single quotes around IND.|||hi,

The datatype for SalesRep code is not defined as its in a view and I am creating the column [Sales Rep Code] with the default value of IND,

e.g

Select 'IND' AS [Sales Rep Code] from test would create a [Sales Rep Code] populated by IND for each row.

I have tried the 'IND' and it appears that it is incorrect syntax, this is beacuse it is closing the string value of the declare statment at the fist ' but I dont have a way around this.

Any Ideas|||Hi thanks for everyones help finally got it working but I still have one problem in that it is over 4000 carachters long and the @.test has a maximum of 4000 carachters is there any way around this.

Thanks

Sunday, February 19, 2012

Add Column to table in merge and transactional rep

Hi,
I have a table that is in both merge and transactional replication and I
would like to add a column to it. Typically, when I add columns to tables in
replication they only exist in one table, so I just go to the publication
properties and add it use the add column button. This time I am a unsure of
how to proceed though because I am not convinced that If I add it through the
interface of the merge publication that it will flow through in the
transactional replication.
So my solution is to add this to the merge replication as per normal and
reinitialize the transactional one and I wondered if anyone had an opinion on
this.
OK, through some experimentation I found that when I go to add a column to
one publication it allows you to choose any others that are applicable, so I
did and that worked great.

Add Article To Trans Rep

Greetings again,
I am trying to add a table to a publication that already has a subscriber and have that table replicate to the subscriber.
2 servers, win2000, SQL 2000 all sp's applied.
1 server is the publisher and the 2nd is both the distributor and subscriber.
I went through the publication's properties page (em-replication-right click- properties) and added the table to the published articles list.
Then on the good advice of Paul Ibson in an earlier post to this newsgroup I created a new snapshot of the table and had
the dist. agent apply it. All went well.
However, new data in the table is not being replicated.
I've exhausted BOL and the web searches. Any recommendations as to the exact process I should follow would be greatly appreciated.
Thank you for your time.
Joe,
have you run the distribution agent? Run sp_browsereplcmds in the
distribution database to see if your new rows are waiting there. If they are
then just running the distribution agent will fix it. If not, then perhaps
the log reader is disabled?
HTH,
Paul Ibison