Showing posts with label column. Show all posts
Showing posts with label column. Show all posts

Monday, March 19, 2012

"Update" in Trigger not working

Hi,

I am trying to concatenate the columns (PrevEmp01, PrevEmp02, PrevEmp03, PrevEmp04, PrevEmp05) into column (ft) using trigger:

CREATE TRIGGER [tg_prevemp_ft_update] ON [tStaffDir_PrevEmp]
FOR INSERT, UPDATE
AS
UPDATE tStaffDir_PrevEmp SET ft = PrevEmp01 + ' ' + PrevEmp02 + ' ' + PrevEmp03 + ' ' + PrevEmp04 + ' ' + PrevEmp05

I would expect the (ft) column will be populated accordingly regardless if any of the columns are (Null).
But the Trigger will only work when all the 5 columns are populated. If one of the column is (Null), the (ft) column will be (Null) too.

Please advise. Many Thanks.

Try this:

CREATE TRIGGER [tg_prevemp_ft_update]ON [tStaffDir_PrevEmp]FOR INSERT,UPDATEASUPDATE tStaffDir_PrevEmpSET ft =ISNULL(PrevEmp01,'') +' ' +ISNULL(PrevEmp02,'') +' ' +ISNULL(PrevEmp03,'') +' ' +ISNULL(PrevEmp04,'') +' ' +ISNULL(PrevEmp05,'')

Good luck.

|||

Thanks! It worked.

Friday, March 16, 2012

"Text column data incomplete" error during replication

I'm doing a transactional replication for the first time between 2
servers.
After 14 minutes of running (according to the logs), the replicaton
crashes. This is what I find in the log file generated by the
distribution agent. It starts bulk copying data from many tables until
it finally crashes on the first copy.
Any ideas why?
What does it mean 'Text column data incomplete'.
Table Parcel has 2 text columns that can be NULL.
Also, at the time the replication was taking place, it is possible
other transactions might have been being added/deleted from
Parcel......could this produce this type of error?
Here goes the erro log:
Bulk copying data into table 'Parcel'
:
Bulk copying data into table 'Item Specific Cost Factor'
:
Bulk copying data into table 'Item Appraisal Details'
:
:
Agent message code 20037. The process could not bulk copy into table
'"Parcel"'.
[6/16/2004 10:37:08 AM]SERVER.distribution: {call
sp_MSadd_distribution_history(4, 6, ?, ?, 0, 0, 0.00, 0x01, 1, ?,
414, 0x01, 0x01)}
Adding alert to msdb..sysreplicationalerts: ErrorId = 9,
Transaction Seqno = 0004158900000066000100000001, Command ID = 414
Message: Replication-Replication Distribution Subsystem: agent
SERVER-Acadia_Final_Assessor-Acadia_Final_Assessor-68.216.171.51-4
failed.
The process could not bulk copy into table '"Parcel"'.[6/16/2004
10:37:08 AM]SERVER.distribution: {call sp_MSadd_repl_alert(3, 4, 9,
14151, ?, 414, N'SERVER', N'Acadia_Final_Assessor', N'68.216.171.51',
N'TestDB', ?)}
ErrorId = 9, SourceTypeId = 1
ErrorCode = ''
ErrorText = 'select * from "Parcel Item" where 1 = 2
'
[6/16/2004 10:37:08 AM]SERVER.distribution: {call
sp_MSadd_repl_error(9, 0, 1, ?, N'', ?)}
Category:COMMAND
Source: Failed Command
Number:
Message: select * from "Parcel Item" where 1 = 2
ErrorId = 9, SourceTypeId = 4
ErrorCode = 'S1000'
ErrorText = 'Text column data incomplete'
[6/16/2004 10:37:09 AM]SERVER.distribution: {call
sp_MSadd_repl_error(9, 0, 4, ?, N'S1000', ?)}
Category:ODBC
Source: 68.216.171.51
Number: S1000
Message: Text column data incomplete
ErrorId = 9, SourceTypeId = 4
ErrorCode = 'S1000'
ErrorText = 'Text column data incomplete'
[6/16/2004 10:37:09 AM]SERVER.distribution: {call
sp_MSadd_repl_error(9, 0, 4, ?, N'S1000', ?)}
Category:ODBC
Source: ODBC SQL Server Driver
Number: S1000
Message: Text column data incomplete
ErrorId = 9, SourceTypeId = 4
ErrorCode = 'S1000'
ErrorText = 'Text column data incomplete'
[6/16/2004 10:37:09 AM]SERVER.distribution: {call
sp_MSadd_repl_error(9, 0, 4, ?, N'S1000', ?)}
Category:ODBC
Source: ODBC SQL Server Driver
Number: S1000
Message: Text column data incomplete
ErrorId = 9, SourceTypeId = 4
ErrorCode = 'S1000'
ErrorText = 'Text column data incomplete'
[6/16/2004 10:37:09 AM]SERVER.distribution: {call
sp_MSadd_repl_error(9, 0, 4, ?, N'S1000', ?)}
Category:ODBC
Source: ODBC SQL Server Driver
Number: S1000
Message: Text column data incomplete
ErrorId = 9, SourceTypeId = 4
ErrorCode = 'S1000'
ErrorText = 'Text column data incomplete'
[6/16/2004 10:37:09 AM]SERVER.distribution: {call
sp_MSadd_repl_error(9, 0, 4, ?, N'S1000', ?)}
Category:ODBC
Source: ODBC SQL Server Driver
Number: S1000
Message: Text column data incomplete
[6/16/2004 10:37:09 AM]68.216.171.51.TestDB: exec
dbo.sp_MSupdatelastsyncinfo N'SERVER',N'Acadia_Final_Assessor',
N'Acadia_Final_Assessor', 0, 6, N'The process could not bulk copy into
table ''"Parcel"''.'
Disconnecting from Subscriber '......'
Disconnecting from Distributor 'SERVER'
Disconnecting from Distributor History 'SERVER'
is the database collations on the subscriber and publisher the same?
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"Rocio" <rocio.katsanis@.softwareservices.net> wrote in message
news:7b914006.0406161119.2936cea7@.posting.google.c om...
> I'm doing a transactional replication for the first time between 2
> servers.
> After 14 minutes of running (according to the logs), the replicaton
> crashes. This is what I find in the log file generated by the
> distribution agent. It starts bulk copying data from many tables until
> it finally crashes on the first copy.
> Any ideas why?
> What does it mean 'Text column data incomplete'.
> Table Parcel has 2 text columns that can be NULL.
> Also, at the time the replication was taking place, it is possible
> other transactions might have been being added/deleted from
> Parcel......could this produce this type of error?
> Here goes the erro log:
> Bulk copying data into table 'Parcel'
> :
> Bulk copying data into table 'Item Specific Cost Factor'
> :
> Bulk copying data into table 'Item Appraisal Details'
> :
> :
> Agent message code 20037. The process could not bulk copy into table
> '"Parcel"'.
> [6/16/2004 10:37:08 AM]SERVER.distribution: {call
> sp_MSadd_distribution_history(4, 6, ?, ?, 0, 0, 0.00, 0x01, 1, ?,
> 414, 0x01, 0x01)}
> Adding alert to msdb..sysreplicationalerts: ErrorId = 9,
> Transaction Seqno = 0004158900000066000100000001, Command ID = 414
> Message: Replication-Replication Distribution Subsystem: agent
> SERVER-Acadia_Final_Assessor-Acadia_Final_Assessor-68.216.171.51-4
> failed.
> The process could not bulk copy into table '"Parcel"'.[6/16/2004
> 10:37:08 AM]SERVER.distribution: {call sp_MSadd_repl_alert(3, 4, 9,
> 14151, ?, 414, N'SERVER', N'Acadia_Final_Assessor', N'68.216.171.51',
> N'TestDB', ?)}
> ErrorId = 9, SourceTypeId = 1
> ErrorCode = ''
> ErrorText = 'select * from "Parcel Item" where 1 = 2
> '
> [6/16/2004 10:37:08 AM]SERVER.distribution: {call
> sp_MSadd_repl_error(9, 0, 1, ?, N'', ?)}
> Category:COMMAND
> Source: Failed Command
> Number:
> Message: select * from "Parcel Item" where 1 = 2
> ErrorId = 9, SourceTypeId = 4
> ErrorCode = 'S1000'
> ErrorText = 'Text column data incomplete'
> [6/16/2004 10:37:09 AM]SERVER.distribution: {call
> sp_MSadd_repl_error(9, 0, 4, ?, N'S1000', ?)}
> Category:ODBC
> Source: 68.216.171.51
> Number: S1000
> Message: Text column data incomplete
> ErrorId = 9, SourceTypeId = 4
> ErrorCode = 'S1000'
> ErrorText = 'Text column data incomplete'
> [6/16/2004 10:37:09 AM]SERVER.distribution: {call
> sp_MSadd_repl_error(9, 0, 4, ?, N'S1000', ?)}
> Category:ODBC
> Source: ODBC SQL Server Driver
> Number: S1000
> Message: Text column data incomplete
> ErrorId = 9, SourceTypeId = 4
> ErrorCode = 'S1000'
> ErrorText = 'Text column data incomplete'
> [6/16/2004 10:37:09 AM]SERVER.distribution: {call
> sp_MSadd_repl_error(9, 0, 4, ?, N'S1000', ?)}
> Category:ODBC
> Source: ODBC SQL Server Driver
> Number: S1000
> Message: Text column data incomplete
> ErrorId = 9, SourceTypeId = 4
> ErrorCode = 'S1000'
> ErrorText = 'Text column data incomplete'
> [6/16/2004 10:37:09 AM]SERVER.distribution: {call
> sp_MSadd_repl_error(9, 0, 4, ?, N'S1000', ?)}
> Category:ODBC
> Source: ODBC SQL Server Driver
> Number: S1000
> Message: Text column data incomplete
> ErrorId = 9, SourceTypeId = 4
> ErrorCode = 'S1000'
> ErrorText = 'Text column data incomplete'
> [6/16/2004 10:37:09 AM]SERVER.distribution: {call
> sp_MSadd_repl_error(9, 0, 4, ?, N'S1000', ?)}
> Category:ODBC
> Source: ODBC SQL Server Driver
> Number: S1000
> Message: Text column data incomplete
> [6/16/2004 10:37:09 AM]68.216.171.51.TestDB: exec
> dbo.sp_MSupdatelastsyncinfo N'SERVER',N'Acadia_Final_Assessor',
> N'Acadia_Final_Assessor', 0, 6, N'The process could not bulk copy into
> table ''"Parcel"''.'
> Disconnecting from Subscriber '......'
> Disconnecting from Distributor 'SERVER'
> Disconnecting from Distributor History 'SERVER'
|||Hi Hillary,
I treid the same replication 3 more times, and the erro I got on those 3
times was different than the one I published here. Now the error is:
Category:SQLSERVER
Source: <IP of subscriber...>
Number: 2812
Message: Could not find stored procedure 'sp_MSupd_Entity Address'.
[6/16/2004 8:24:39 PM]68.216.171.51.TestDB: exec
dbo.sp_MSupdatelastsyncinfo N'SERVER',N'Acadia_Final_Assessor',
N'Acadia_Final_Assessor', 0, 6, N'Error at parameter 199 during
datastream processing of parameterized command.'
Disconnecting from Subscriber '<IP of subscriber...>'
Disconnecting from Distributor 'SERVER'
Disconnecting from Distributor History 'SERVER'
If I looked carefully at this log file, and it seems to me that such
stored procedure is somehow created:
[6/16/2004 8:01:12 PM]<IP of subscriber...>.TestDB: create procedure
"[sp_MSupd_Entity Address]"
@.c1 int,@.c2 int,@.c3 int,@.c4 int,@.c5 int,@.c6 char(4),@.c7 int,@.c8 bit,@.c9
int,@.c10 varchar(500),@.pkc1 int
,@.bitmap binary(2)
as
if substring(@.bitmap,1,1) & 1 = 1
begin
update "Entity Address" set
"Address ID" = case substring(@.bitmap,1,1) & 1 when 1 then @.c1 else
"Address ID" end
,"Entity ID" = case substring(@.bitmap,1,1) & 2 when 2 then @.c2 else
"Entity ID" end
,"City ID" = case substring(@.bitmap,1,1) & 4 when 4 then @.c3 else "City
ID" end
,"State ID" = case substring(@.bitmap,1,1) & 8 when 8 then @.c4 else
"State ID" end
,"Postal Code ID" = case substring(@.bitmap,1,1) & 16 when 16 then @.c5
else "Postal Code ID" end
,"Zip Last 4" = case substring(@.bitmap,1,1) & 32 when 32 then @.c6 else
"Zip Last 4" end
,"Country ID" = case substring(@.bitmap,1,1) & 64 when 64 then @.c7 else
"Country ID" end
,"Primary Address" = case substring(@.bitmap,1,1) & 128 when 128 then @.c8
else "Primary Address" end
,"Address Type ID" = case substring(@.bitmap,2,1) & 1 when 1 then @.c9
else "Address Type ID" end
,"Address Lines" = case substring(@.bitmap,2,1) & 2 when 2 then @.c10 else
"Address Lines" end
where "Address ID" = @.pkc1
if @.@.rowcount = 0
if @.@.microsoftversion>0x07320000
exec sp_MSreplraiserror 20598
end
else
begin
update "Entity Address" set
"Entity ID" = case substring(@.bitmap,1,1) & 2 when 2 then @.c2 else
"Entity ID" end
,"City ID" = case substring(@.bitmap,1,1) & 4 when 4 then @.c3 else "City
ID" end
,"State ID" = case substring(@.bitmap,1,1) & 8 when 8 then @.c4 else
"State ID" end
,"Postal Code ID" = case substring(@.bitmap,1,1) & 16 when 16 then @.c5
else "Postal Code ID" end
,"Zip Last 4" = case substring(@.bitmap,1,1) & 32 when 32 then @.c6 else
"Zip Last 4" end
,"Country ID" = case substring(@.bitmap,1,1) & 64 when 64 then @.c7 else
"Country ID" end
,"Primary Address" = case substring(@.bitmap,1,1) & 128 when 128 then @.c8
else "Primary Address" end
,"Address Type ID" = case substring(@.bitmap,2,1) & 1 when 1 then @.c9
else "Address Type ID" end
,"Address Lines" = case substring(@.bitmap,2,1) & 2 when 2 then @.c10 else
"Address Lines" end
where "Address ID" = @.pkc1
if @.@.rowcount = 0
if @.@.microsoftversion>0x07320000
exec sp_MSreplraiserror 20598
end
however, if I look at TestDB in my subscriber, I can find
[sp_MSupd_Entity Address] but not sp_MSupd_Entity Address, note one is
with brackets, the other not.
why 2 sp's anyway (with & without brackets)?
how can I control the creation of this procedure? I looked at the
properties tab of this publictaion at the Publisher, under Article
Entity Address, and make sure all the options are selected (e.g. Replace
INSERT commands with this stored procedure, etc).
The only option I could not access is the one at the very bottom that
causes replication to use the columns name. It was just enabled.
Any ideas?
btw: your book about Transactional & Snapshot replication looks good, I
haven't found a good book on replication yet! Is it out already?
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
|||on your publisher do this
sp_scriptpublicationcustomprocs 'publicationName'
then in your results pan, copy the results and then paste them into another ISQLW window which you open into your subsciption database. then execute this script there.
Restart your distribution agent.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
"Rocio Katsanis" wrote:

> Hi Hillary,
> I treid the same replication 3 more times, and the erro I got on those 3
> times was different than the one I published here. Now the error is:
> Category:SQLSERVER
> Source: <IP of subscriber...>
> Number: 2812
> Message: Could not find stored procedure 'sp_MSupd_Entity Address'.
> [6/16/2004 8:24:39 PM]68.216.171.51.TestDB: exec
> dbo.sp_MSupdatelastsyncinfo N'SERVER',N'Acadia_Final_Assessor',
> N'Acadia_Final_Assessor', 0, 6, N'Error at parameter 199 during
> datastream processing of parameterized command.'
> Disconnecting from Subscriber '<IP of subscriber...>'
> Disconnecting from Distributor 'SERVER'
> Disconnecting from Distributor History 'SERVER'
> If I looked carefully at this log file, and it seems to me that such
> stored procedure is somehow created:
> [6/16/2004 8:01:12 PM]<IP of subscriber...>.TestDB: create procedure
> "[sp_MSupd_Entity Address]"
> @.c1 int,@.c2 int,@.c3 int,@.c4 int,@.c5 int,@.c6 char(4),@.c7 int,@.c8 bit,@.c9
> int,@.c10 varchar(500),@.pkc1 int
> ,@.bitmap binary(2)
> as
> if substring(@.bitmap,1,1) & 1 = 1
> begin
> update "Entity Address" set
> "Address ID" = case substring(@.bitmap,1,1) & 1 when 1 then @.c1 else
> "Address ID" end
> ,"Entity ID" = case substring(@.bitmap,1,1) & 2 when 2 then @.c2 else
> "Entity ID" end
> ,"City ID" = case substring(@.bitmap,1,1) & 4 when 4 then @.c3 else "City
> ID" end
> ,"State ID" = case substring(@.bitmap,1,1) & 8 when 8 then @.c4 else
> "State ID" end
> ,"Postal Code ID" = case substring(@.bitmap,1,1) & 16 when 16 then @.c5
> else "Postal Code ID" end
> ,"Zip Last 4" = case substring(@.bitmap,1,1) & 32 when 32 then @.c6 else
> "Zip Last 4" end
> ,"Country ID" = case substring(@.bitmap,1,1) & 64 when 64 then @.c7 else
> "Country ID" end
> ,"Primary Address" = case substring(@.bitmap,1,1) & 128 when 128 then @.c8
> else "Primary Address" end
> ,"Address Type ID" = case substring(@.bitmap,2,1) & 1 when 1 then @.c9
> else "Address Type ID" end
> ,"Address Lines" = case substring(@.bitmap,2,1) & 2 when 2 then @.c10 else
> "Address Lines" end
> where "Address ID" = @.pkc1
> if @.@.rowcount = 0
> if @.@.microsoftversion>0x07320000
> exec sp_MSreplraiserror 20598
> end
> else
> begin
> update "Entity Address" set
> "Entity ID" = case substring(@.bitmap,1,1) & 2 when 2 then @.c2 else
> "Entity ID" end
> ,"City ID" = case substring(@.bitmap,1,1) & 4 when 4 then @.c3 else "City
> ID" end
> ,"State ID" = case substring(@.bitmap,1,1) & 8 when 8 then @.c4 else
> "State ID" end
> ,"Postal Code ID" = case substring(@.bitmap,1,1) & 16 when 16 then @.c5
> else "Postal Code ID" end
> ,"Zip Last 4" = case substring(@.bitmap,1,1) & 32 when 32 then @.c6 else
> "Zip Last 4" end
> ,"Country ID" = case substring(@.bitmap,1,1) & 64 when 64 then @.c7 else
> "Country ID" end
> ,"Primary Address" = case substring(@.bitmap,1,1) & 128 when 128 then @.c8
> else "Primary Address" end
> ,"Address Type ID" = case substring(@.bitmap,2,1) & 1 when 1 then @.c9
> else "Address Type ID" end
> ,"Address Lines" = case substring(@.bitmap,2,1) & 2 when 2 then @.c10 else
> "Address Lines" end
> where "Address ID" = @.pkc1
> if @.@.rowcount = 0
> if @.@.microsoftversion>0x07320000
> exec sp_MSreplraiserror 20598
> end
> however, if I look at TestDB in my subscriber, I can find
> [sp_MSupd_Entity Address] but not sp_MSupd_Entity Address, note one is
> with brackets, the other not.
> why 2 sp's anyway (with & without brackets)?
> how can I control the creation of this procedure? I looked at the
> properties tab of this publictaion at the Publisher, under Article
> Entity Address, and make sure all the options are selected (e.g. Replace
> INSERT commands with this stored procedure, etc).
> The only option I could not access is the one at the very bottom that
> causes replication to use the columns name. It was just enabled.
> Any ideas?
> btw: your book about Transactional & Snapshot replication looks good, I
> haven't found a good book on replication yet! Is it out already?
>
> *** Sent via Devdex http://www.devdex.com ***
> Don't just participate in USENET...get rewarded for it!
>

"SUM" of a varchar column?

I have a table that contains a number of columns containing either a varchar
value, or null. There are multiple rows per grouping. I would like to colapse
the multiple rows into a single row, either by appending the strings to each
other, or simply selecting the first (or last) one.
If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work, for
obvious reasons. I thought MAX would work, but MAX returns only one value for
all of the columns (as opposed to one per column) and the rest are left as
null.
Any suggestions?
Here's an example...
The table contains this data, all items are varchar
32611317
3261Non-Client
32612
3261mmarkowitz
I'd like to turn this into...
3261 1317 Non-client 2 mmarkowitz
|||This looks like a PIVOT. Can you flatten this table out on the client? If
not, see http://www.aspfaq.com/2462
http://www.aspfaq.com/
(Reverse address to reply.)
"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:7838E3D4-CD8D-46EB-A75F-D069B30EE9AB@.microsoft.com...
> I have a table that contains a number of columns containing either a
varchar
> value, or null. There are multiple rows per grouping. I would like to
colapse
> the multiple rows into a single row, either by appending the strings to
each
> other, or simply selecting the first (or last) one.
> If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work,
for
> obvious reasons. I thought MAX would work, but MAX returns only one value
for
> all of the columns (as opposed to one per column) and the rest are left as
> null.
> Any suggestions?
|||"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:DD2FA7A5-A0F2-4BFF-85E9-42533F4E423C@.microsoft.com...
> Here's an example...
> The table contains this data, all items are varchar
>
> 3261 1317
> 3261 Non-Client
> 3261 2
> 3261 mmarkowitz
> I'd like to turn this into...
> 3261 1317 Non-client 2 mmarkowitz
I'm not sure if this will help, but you may want to take a look at the
GROUP BY WITH ROLLUP and WITH CUBE commands. It may work for what you are
after.
SELECT Col1, Max(Col2)
FROM tablename
GROUP BY Col1
WITH ROLLUP
HTH
Rick Sawtell
MCT, MCSD, MCDBA
|||SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
FROM YourTable
GROUP BY col1
David Portas
SQL Server MVP
|||I don't think this will work, he wants to flatten one ofthe two columns in
his table out into multiple columns...
http://www.aspfaq.com/
(Reverse address to reply.)
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1103306604.369012.58920@.z14g2000cwz.googlegro ups.com...
> SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
> FROM YourTable
> GROUP BY col1
> --
> David Portas
> SQL Server MVP
> --
>
|||OK. Looks to me like 5 columns but I guess that's just presentational ;-)
Tough to pivot without an explicit attribute for the column.
David Portas
SQL Server MVP
|||"Aaron [SQL Server MVP]" wrote:

> This looks like a PIVOT.
Actually it is the RESULT of a pivot, which is why it is spread out
vertically like that.
But I did figure out a "trick". After reading the page you sent, I combined
their technique of ISNULL (instead of CASE) with MIN, and presto.
Thanks!
(anyone interested in the code?)

"SUM" of a varchar column?

I have a table that contains a number of columns containing either a varchar
value, or null. There are multiple rows per grouping. I would like to colapse
the multiple rows into a single row, either by appending the strings to each
other, or simply selecting the first (or last) one.
If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work, for
obvious reasons. I thought MAX would work, but MAX returns only one value for
all of the columns (as opposed to one per column) and the rest are left as
null.
Any suggestions?Here's an example...
The table contains this data, all items are varchar
3261 1317
3261 Non-Client
3261 2
3261 mmarkowitz
I'd like to turn this into...
3261 1317 Non-client 2 mmarkowitz|||This looks like a PIVOT. Can you flatten this table out on the client? If
not, see http://www.aspfaq.com/2462
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:7838E3D4-CD8D-46EB-A75F-D069B30EE9AB@.microsoft.com...
> I have a table that contains a number of columns containing either a
varchar
> value, or null. There are multiple rows per grouping. I would like to
colapse
> the multiple rows into a single row, either by appending the strings to
each
> other, or simply selecting the first (or last) one.
> If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work,
for
> obvious reasons. I thought MAX would work, but MAX returns only one value
for
> all of the columns (as opposed to one per column) and the rest are left as
> null.
> Any suggestions?|||"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:DD2FA7A5-A0F2-4BFF-85E9-42533F4E423C@.microsoft.com...
> Here's an example...
> The table contains this data, all items are varchar
>
> 3261 1317
> 3261 Non-Client
> 3261 2
> 3261 mmarkowitz
> I'd like to turn this into...
> 3261 1317 Non-client 2 mmarkowitz
I'm not sure if this will help, but you may want to take a look at the
GROUP BY WITH ROLLUP and WITH CUBE commands. It may work for what you are
after.
SELECT Col1, Max(Col2)
FROM tablename
GROUP BY Col1
WITH ROLLUP
HTH
Rick Sawtell
MCT, MCSD, MCDBA|||SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
FROM YourTable
GROUP BY col1
--
David Portas
SQL Server MVP
--|||I don't think this will work, he wants to flatten one ofthe two columns in
his table out into multiple columns...
--
http://www.aspfaq.com/
(Reverse address to reply.)
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1103306604.369012.58920@.z14g2000cwz.googlegroups.com...
> SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
> FROM YourTable
> GROUP BY col1
> --
> David Portas
> SQL Server MVP
> --
>|||OK. Looks to me like 5 columns but I guess that's just presentational ;-)
Tough to pivot without an explicit attribute for the column.
--
David Portas
SQL Server MVP
--|||"Aaron [SQL Server MVP]" wrote:
> This looks like a PIVOT.
Actually it is the RESULT of a pivot, which is why it is spread out
vertically like that.
But I did figure out a "trick". After reading the page you sent, I combined
their technique of ISNULL (instead of CASE) with MIN, and presto.
Thanks!
(anyone interested in the code?)

Sunday, March 11, 2012

"Select TOP " question

I ran two query: one with order by, one does not.
Note that a clustered index has been build on column
DCN, CO_cd. No index on Sta_Rsn_Cd.
1) select top 1 DCN, CO_Cd, Dept from tblTest
where Dept = '212' and Sta_Rsn_Cd <> 'TRN' and Sta_Rsn_Cd <> 'NDF'
and Sufx = 'C'
and check_out <> 'Y'
order by Sta_Rsn_Cd
2) select top 1 DCN, CO_Cd, Dept from tblTest
where Dept = '212' and Sta_Rsn_Cd <> 'TRN' and Sta_Rsn_Cd <> 'NDF'
and Sufx = 'C'
and check_out <> 'Y'
In BOL
"If a SELECT statement that includes TOP also has an ORDER BY clause,
the rows to be returned are selected from the ordered result set. The
entire result set is built in the specified order and the top n rows in
the ordered result set are returned."
It seems that 2) would run faster than 1). When I run,
1) is faster than 2). I use SQL 2000. Any comments?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!It's hard to say from this. Can you run the SHOWPLAN for each of these
commands and include that here as well.
Rick Sawtell
"YB" <yb@.dex.com> wrote in message
news:eidd8xPoEHA.2948@.TK2MSFTNGP11.phx.gbl...
> I ran two query: one with order by, one does not.
> Note that a clustered index has been build on column
> DCN, CO_cd. No index on Sta_Rsn_Cd.
> 1) select top 1 DCN, CO_Cd, Dept from tblTest
> where Dept = '212' and Sta_Rsn_Cd <> 'TRN' and Sta_Rsn_Cd <> 'NDF'
> and Sufx = 'C'
> and check_out <> 'Y'
> order by Sta_Rsn_Cd
> 2) select top 1 DCN, CO_Cd, Dept from tblTest
> where Dept = '212' and Sta_Rsn_Cd <> 'TRN' and Sta_Rsn_Cd <> 'NDF'
> and Sufx = 'C'
> and check_out <> 'Y'
> In BOL
> "If a SELECT statement that includes TOP also has an ORDER BY clause,
> the rows to be returned are selected from the ordered result set. The
> entire result set is built in the specified order and the top n rows in
> the ordered result set are returned."
> It seems that 2) would run faster than 1). When I run,
> 1) is faster than 2). I use SQL 2000. Any comments?
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Thursday, March 8, 2012

"Right" section of BorderStyle not working in last column

I have a multi-column report (with a header). I'm trying to draw a 1pt
border around the entire header. Not the report or table, just the header.
All of the sections of the border appear correctly except the sections in
the last column to the right. The "right" section of the last column does
not display in any mode.
Has anyone run into this? Is there a workaround?
Thanks!You can get a "clipped" or "missing" information in the last column when the
following is not true:
PageWidth - Left Margin - Right Marging >= (#Columns * ColumnWidth) +
((#Columns -1) * Column Spacing).
Please check how your multi column report is setup.
--
Bruce Johnson [MSFT]
Microsoft SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Michael Creamer" <MichaelCreamer@.discussions.microsoft.com> wrote in
message news:425BF87E-437C-4B97-88B2-28207E96C53D@.microsoft.com...
>I have a multi-column report (with a header). I'm trying to draw a 1pt
> border around the entire header. Not the report or table, just the
> header.
> All of the sections of the border appear correctly except the sections in
> the last column to the right. The "right" section of the last column does
> not display in any mode.
> Has anyone run into this? Is there a workaround?
> Thanks!

"pivotting" a table...

Greetings!
I've got a simple list of id's and descriptions that I'd like to rotate so
that each column is the id there exists one row which is the description for
that column.
Basically something like this:
ID Description
--
1 Bob
2 Franks
3 Harry
And I'd like this:
1 2 3
--
Bob Franks Harry
I looked at the PIVOT operator with SQL Server 2005 but this seems more for
aggregating data. What SQL would you use to accomplish this?
Thanks.
Daniel.Dan
CREATE TABLE #tmp (ID INT NOT NULL PRIMARY KEY, Description VARCHAR(20))
GO
INSERT INTO #tmp VALUES (1,'Bob')
INSERT INTO #tmp VALUES(2,'Franks')
INSERT INTO #tmp VALUES(3,'Harry')
SELECT *
FROM #tmp
PIVOT
(
MAX(Description)
FOR ID IN([1],[2],[3])
) AS PVT
"Dan Bass" <na> wrote in message
news:u94YnMqHHHA.4760@.TK2MSFTNGP03.phx.gbl...
> Greetings!
> I've got a simple list of id's and descriptions that I'd like to rotate so
> that each column is the id there exists one row which is the description
> for that column.
> Basically something like this:
> ID Description
> --
> 1 Bob
> 2 Franks
> 3 Harry
> And I'd like this:
> 1 2 3
> --
> Bob Franks Harry
>
> I looked at the PIVOT operator with SQL Server 2005 but this seems more
> for aggregating data. What SQL would you use to accomplish this?
> Thanks.
> Daniel.
>|||Thanks Uri!
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:excr1ZqHHHA.3952@.TK2MSFTNGP02.phx.gbl...
> Dan
> CREATE TABLE #tmp (ID INT NOT NULL PRIMARY KEY, Description VARCHAR(20))
> GO
> INSERT INTO #tmp VALUES (1,'Bob')
> INSERT INTO #tmp VALUES(2,'Franks')
> INSERT INTO #tmp VALUES(3,'Harry')
>
> SELECT *
> FROM #tmp
> PIVOT
> (
> MAX(Description)
> FOR ID IN([1],[2],[3])
> ) AS PVT
> "Dan Bass" <na> wrote in message
> news:u94YnMqHHHA.4760@.TK2MSFTNGP03.phx.gbl...
>> Greetings!
>> I've got a simple list of id's and descriptions that I'd like to rotate
>> so that each column is the id there exists one row which is the
>> description for that column.
>> Basically something like this:
>> ID Description
>> --
>> 1 Bob
>> 2 Franks
>> 3 Harry
>> And I'd like this:
>> 1 2 3
>> --
>> Bob Franks Harry
>>
>> I looked at the PIVOT operator with SQL Server 2005 but this seems more
>> for aggregating data. What SQL would you use to accomplish this?
>> Thanks.
>> Daniel.
>|||Dan
More dynamic
DECLARE @.T AS TABLE(y INT NOT NULL PRIMARY KEY);
DECLARE
@.cols AS NVARCHAR(MAX),
@.y AS INT,
@.sql AS NVARCHAR(MAX);
SET @.cols = STUFF(
(SELECT N',' + QUOTENAME(y) AS [text()]
FROM (SELECT id AS y FROM #tmp) AS Y
ORDER BY y
FOR XML PATH('')),
1, 1, N'');
SET @.sql = N'SELECT *
FROM (SELECT *
FROM #tmp) AS D
PIVOT(MAX(Description) FOR id IN(' + @.cols + N')) AS P;';
EXEC sp_executesql @.sql;
"Dan Bass" <na> wrote in message
news:%23$IJBeqHHHA.3268@.TK2MSFTNGP04.phx.gbl...
> Thanks Uri!
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:excr1ZqHHHA.3952@.TK2MSFTNGP02.phx.gbl...
>> Dan
>> CREATE TABLE #tmp (ID INT NOT NULL PRIMARY KEY, Description VARCHAR(20))
>> GO
>> INSERT INTO #tmp VALUES (1,'Bob')
>> INSERT INTO #tmp VALUES(2,'Franks')
>> INSERT INTO #tmp VALUES(3,'Harry')
>>
>> SELECT *
>> FROM #tmp
>> PIVOT
>> (
>> MAX(Description)
>> FOR ID IN([1],[2],[3])
>> ) AS PVT
>> "Dan Bass" <na> wrote in message
>> news:u94YnMqHHHA.4760@.TK2MSFTNGP03.phx.gbl...
>> Greetings!
>> I've got a simple list of id's and descriptions that I'd like to rotate
>> so that each column is the id there exists one row which is the
>> description for that column.
>> Basically something like this:
>> ID Description
>> --
>> 1 Bob
>> 2 Franks
>> 3 Harry
>> And I'd like this:
>> 1 2 3
>> --
>> Bob Franks Harry
>>
>> I looked at the PIVOT operator with SQL Server 2005 but this seems more
>> for aggregating data. What SQL would you use to accomplish this?
>> Thanks.
>> Daniel.
>>
>

"pivotting" a table...

Greetings!
I've got a simple list of id's and descriptions that I'd like to rotate so
that each column is the id there exists one row which is the description for
that column.
Basically something like this:
ID Description
1 Bob
2 Franks
3 Harry
And I'd like this:
1 2 3
Bob Franks Harry
I looked at the PIVOT operator with SQL Server 2005 but this seems more for
aggregating data. What SQL would you use to accomplish this?
Thanks.
Daniel.
Dan
CREATE TABLE #tmp (ID INT NOT NULL PRIMARY KEY, Description VARCHAR(20))
GO
INSERT INTO #tmp VALUES (1,'Bob')
INSERT INTO #tmp VALUES(2,'Franks')
INSERT INTO #tmp VALUES(3,'Harry')
SELECT *
FROM #tmp
PIVOT
(
MAX(Description)
FOR ID IN([1],[2],[3])
) AS PVT
"Dan Bass" <na> wrote in message
news:u94YnMqHHHA.4760@.TK2MSFTNGP03.phx.gbl...
> Greetings!
> I've got a simple list of id's and descriptions that I'd like to rotate so
> that each column is the id there exists one row which is the description
> for that column.
> Basically something like this:
> ID Description
> --
> 1 Bob
> 2 Franks
> 3 Harry
> And I'd like this:
> 1 2 3
> --
> Bob Franks Harry
>
> I looked at the PIVOT operator with SQL Server 2005 but this seems more
> for aggregating data. What SQL would you use to accomplish this?
> Thanks.
> Daniel.
>
|||Thanks Uri!
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:excr1ZqHHHA.3952@.TK2MSFTNGP02.phx.gbl...
> Dan
> CREATE TABLE #tmp (ID INT NOT NULL PRIMARY KEY, Description VARCHAR(20))
> GO
> INSERT INTO #tmp VALUES (1,'Bob')
> INSERT INTO #tmp VALUES(2,'Franks')
> INSERT INTO #tmp VALUES(3,'Harry')
>
> SELECT *
> FROM #tmp
> PIVOT
> (
> MAX(Description)
> FOR ID IN([1],[2],[3])
> ) AS PVT
> "Dan Bass" <na> wrote in message
> news:u94YnMqHHHA.4760@.TK2MSFTNGP03.phx.gbl...
>
|||Dan
More dynamic
DECLARE @.T AS TABLE(y INT NOT NULL PRIMARY KEY);
DECLARE
@.cols AS NVARCHAR(MAX),
@.y AS INT,
@.sql AS NVARCHAR(MAX);
SET @.cols = STUFF(
(SELECT N',' + QUOTENAME(y) AS [text()]
FROM (SELECT id AS y FROM #tmp) AS Y
ORDER BY y
FOR XML PATH('')),
1, 1, N'');
SET @.sql = N'SELECT *
FROM (SELECT *
FROM #tmp) AS D
PIVOT(MAX(Description) FOR id IN(' + @.cols + N')) AS P;';
EXEC sp_executesql @.sql;
"Dan Bass" <na> wrote in message
news:%23$IJBeqHHHA.3268@.TK2MSFTNGP04.phx.gbl...
> Thanks Uri!
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:excr1ZqHHHA.3952@.TK2MSFTNGP02.phx.gbl...
>

"pivotting" a table...

Greetings!
I've got a simple list of id's and descriptions that I'd like to rotate so
that each column is the id there exists one row which is the description for
that column.
Basically something like this:
ID Description
--
1 Bob
2 Franks
3 Harry
And I'd like this:
1 2 3
--
Bob Franks Harry
I looked at the PIVOT operator with SQL Server 2005 but this seems more for
aggregating data. What SQL would you use to accomplish this?
Thanks.
Daniel.Dan
CREATE TABLE #tmp (ID INT NOT NULL PRIMARY KEY, Description VARCHAR(20))
GO
INSERT INTO #tmp VALUES (1,'Bob')
INSERT INTO #tmp VALUES(2,'Franks')
INSERT INTO #tmp VALUES(3,'Harry')
SELECT *
FROM #tmp
PIVOT
(
MAX(Description)
FOR ID IN([1],[2],[3])
) AS PVT
"Dan Bass" <na> wrote in message
news:u94YnMqHHHA.4760@.TK2MSFTNGP03.phx.gbl...
> Greetings!
> I've got a simple list of id's and descriptions that I'd like to rotate so
> that each column is the id there exists one row which is the description
> for that column.
> Basically something like this:
> ID Description
> --
> 1 Bob
> 2 Franks
> 3 Harry
> And I'd like this:
> 1 2 3
> --
> Bob Franks Harry
>
> I looked at the PIVOT operator with SQL Server 2005 but this seems more
> for aggregating data. What SQL would you use to accomplish this?
> Thanks.
> Daniel.
>|||Thanks Uri!
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:excr1ZqHHHA.3952@.TK2MSFTNGP02.phx.gbl...
> Dan
> CREATE TABLE #tmp (ID INT NOT NULL PRIMARY KEY, Description VARCHAR(20))
> GO
> INSERT INTO #tmp VALUES (1,'Bob')
> INSERT INTO #tmp VALUES(2,'Franks')
> INSERT INTO #tmp VALUES(3,'Harry')
>
> SELECT *
> FROM #tmp
> PIVOT
> (
> MAX(Description)
> FOR ID IN([1],[2],[3])
> ) AS PVT
> "Dan Bass" <na> wrote in message
> news:u94YnMqHHHA.4760@.TK2MSFTNGP03.phx.gbl...
>|||Dan
More dynamic
DECLARE @.T AS TABLE(y INT NOT NULL PRIMARY KEY);
DECLARE
@.cols AS NVARCHAR(MAX),
@.y AS INT,
@.sql AS NVARCHAR(MAX);
SET @.cols = STUFF(
(SELECT N',' + QUOTENAME(y) AS [text()]
FROM (SELECT id AS y FROM #tmp) AS Y
ORDER BY y
FOR XML PATH('')),
1, 1, N'');
SET @.sql = N'SELECT *
FROM (SELECT *
FROM #tmp) AS D
PIVOT(MAX(Description) FOR id IN(' + @.cols + N')) AS P;';
EXEC sp_executesql @.sql;
"Dan Bass" <na> wrote in message
news:%23$IJBeqHHHA.3268@.TK2MSFTNGP04.phx.gbl...
> Thanks Uri!
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:excr1ZqHHHA.3952@.TK2MSFTNGP02.phx.gbl...
>

Tuesday, March 6, 2012

"Password" data type

Hi,
I have a table which store the UserID and password in SQL
Server 2000.
Right now I use the "varchar" for the password column, but
when someone have the odbc link to the data from access or
crystal report, they can very easy to see all the password.
I am looking for something like in Access, you can put
the "Password" input mask, so when people open the
database, they can only see something like "****".
Thanks
HLHi,
Why dont you create SQL Server based logins, SO that passwords are encryted
and can not be decrypted. This will be the highest security mechnaism you
could go.
Still you could see the below article to encrypt a column.
http://www.mssqlserver.com/faq/general-encrypt.asp
Thanks
Hari
SQL Server MVP
"HL" wrote:

> Hi,
> I have a table which store the UserID and password in SQL
> Server 2000.
> Right now I use the "varchar" for the password column, but
> when someone have the odbc link to the data from access or
> crystal report, they can very easy to see all the password.
> I am looking for something like in Access, you can put
> the "Password" input mask, so when people open the
> database, they can only see something like "****".
> Thanks
> HL
>
>

"Order BY" question

I've got a table that holds real estate data. One of the column holds "category" data. Where there could be 100s of records, there are only four different types of categories:

listing
escrow
evict
rehab

The name of the column is "status". If I do an Order By Status ASC, I get the expected alphabetical listing. However, I would like to list things differently than that. Specifically, I'd like to list all of the records in the table by Status, BUT, list them in this order:

evict

rehab

listing

escrow

Is this doable? Thanks for your help!

Ron

tobias,

The best thing for you to do would be to have a lookup table that stores your "Status" values, and add a column called "SortOrder" to that table -- let this column define the order of the statuses. Then, in your query, join onto the Status table and do an ORDER BY SortOrder. This will also give you the flexibility of modifying the sort order to something else in the future.

|||

Thanks, vito. Forgive my lack of knowledge here, but could give an example of what the SQL select statement what look like that joined two tables and ORDER(ed) BY SortOrder? Thanks for your help.

|||

tobias5:

I've got a table that holds real estate data. One of the column holds "category" data. Where there could be 100s of records, there are only four different types of categories:

listing
escrow
evict
rehab

The name of the column is "status". If I do an Order By Status ASC, I get the expected alphabetical listing. However, I would like to list things differently than that. Specifically, I'd like to list all of the records in the table by Status, BUT, list them in this order:

evict

rehab

listing

escrow

Is this doable? Thanks for your help!

Ron

Vito's suggestion would be to build a lookup table, let's call it Status, that looks like this:

StatusCode SortOrder

evict 3
rehab 4
listing 1
escrow 2

Then your SQL statement would look like this:

SELECT

someColumns

FROM

myTable

INNER JOIN

Status ON myTable.StatusCode = Status.StatusCode

ORDER BY

Status.SortOrder

Alternately, and this is ultimately not as flexible, you could forego the additional table and use a CASE statement for the ordering:

SELECT

someColumns

FROM

myTable
ORDER BY

CASE StatusCode

WHEN 'evict' THEN 3

WHEN 'rehab' THEN 4

WHEN 'listing' THEN 1

WHEN 'escrow' THEN 2

ELSE 5

END

|||

Thanks vito and tmorton. Both of your suggestions worked beautifully.

I VERY much appreciate your help!

Ron

"Order by" error running DBCC DBREINDEX

I'm running a simple DBCC DBREINDEX ('myTable') and I receive the
following error:

"Server: Msg 169, Level 15, State 2, Line 2
A column has been specified more than once in the order by list.
Columns in the order by list must be unique. DBCC execution
completed. If DBCC printed error messages, contact your system
administrator."

I can successfully reindex other tables in this database. I thought
that perhaps I had objects in the database that ended up with the same
name, but I've pretty much ruled that out.

Any suggestions?

Thanks
John D. Morris
mailto://jmorris_42@.hotmail.comjmorris_42@.hotmail.com (John Morris) wrote in message news:<5b4367be.0308050426.10612a9f@.posting.google.com>...
> I'm running a simple DBCC DBREINDEX ('myTable') and I receive the
> following error:
> "Server: Msg 169, Level 15, State 2, Line 2
> A column has been specified more than once in the order by list.
> Columns in the order by list must be unique. DBCC execution
> completed. If DBCC printed error messages, contact your system
> administrator."
> I can successfully reindex other tables in this database. I thought
> that perhaps I had objects in the database that ended up with the same
> name, but I've pretty much ruled that out.
> Any suggestions?
> Thanks
> John D. Morris
> mailto://jmorris_42@.hotmail.com

Followup:

As it turns out, I had a hidden "Hypothetical" index that the index
tuning wizard decided not to clean up when it was done. The only way
to see the index was in sp_helpindex. It did not appear in the object
browser. MS claims this was fixed in SP1...I guess not. Anyway,
dropped the hypothetical index and all is well.

-jdm|||John,

Can you consistently repro the bug?
--
Arun Marathe
Microsoft Corporation

Disclaimers:
(1) This posting is provided "AS IS" with no warranties, and confers no
rights.
(2) Use of included script samples are subject to the terms specified at:
http://www.microsoft.com/info/cpyright.htm

"John D. Morris" <jmorris@.sni.org> wrote in message
news:d034511a.0308051015.60cc849a@.posting.google.c om...
> jmorris_42@.hotmail.com (John Morris) wrote in message
news:<5b4367be.0308050426.10612a9f@.posting.google.com>...
> > I'm running a simple DBCC DBREINDEX ('myTable') and I receive the
> > following error:
> > "Server: Msg 169, Level 15, State 2, Line 2
> > A column has been specified more than once in the order by list.
> > Columns in the order by list must be unique. DBCC execution
> > completed. If DBCC printed error messages, contact your system
> > administrator."
> > I can successfully reindex other tables in this database. I thought
> > that perhaps I had objects in the database that ended up with the same
> > name, but I've pretty much ruled that out.
> > Any suggestions?
> > Thanks
> > John D. Morris
> > mailto://jmorris_42@.hotmail.com
> Followup:
> As it turns out, I had a hidden "Hypothetical" index that the index
> tuning wizard decided not to clean up when it was done. The only way
> to see the index was in sp_helpindex. It did not appear in the object
> browser. MS claims this was fixed in SP1...I guess not. Anyway,
> dropped the hypothetical index and all is well.
> -jdm

"Order by" by parameter in stored procedure

I would like to pass the name of a column to a stored procedure, so the
result of the query would be ordered by that column.
I tried this:
CREATE Procedure ProductsByTab
(
@.TabID int,
@.Order nvarchar (50)
)
AS
SELECT
*
FROM
Product
WHERE
TabID = @.TabID
ORDER BY
@.Order
GO
but I get this message:
Error 1008: The SELECT item identified by the ORDER BY number 1 contains a
variable as part of the expression identifying a column position. Variables
are only allowed when ordering by an expression referencing a column name.
Is it possible to do what I want? What am I doing wrong?
Thank you.i have the same thing but i use a different approach, i pass a flag
representing the numeric order of the field
select * from ttt
order by case @.flag when 1 then name when 2 then description else '' end,
case @.flag when 3 then amount else 0 end,name,description,amount
"Carlos Santos" wrote:

> I would like to pass the name of a column to a stored procedure, so the
> result of the query would be ordered by that column.
> I tried this:
> CREATE Procedure ProductsByTab
> (
> @.TabID int,
> @.Order nvarchar (50)
> )
> AS
> SELECT
> *
> FROM
> Product
> WHERE
> TabID = @.TabID
> ORDER BY
> @.Order
> GO
> but I get this message:
> Error 1008: The SELECT item identified by the ORDER BY number 1 contains a
> variable as part of the expression identifying a column position. Variable
s
> are only allowed when ordering by an expression referencing a column name.
> Is it possible to do what I want? What am I doing wrong?
> Thank you.|||How do I use a variable in an ORDER BY clause?
http://www.aspfaq.com/show.asp?id=2501
AMB
"Carlos Santos" wrote:

> I would like to pass the name of a column to a stored procedure, so the
> result of the query would be ordered by that column.
> I tried this:
> CREATE Procedure ProductsByTab
> (
> @.TabID int,
> @.Order nvarchar (50)
> )
> AS
> SELECT
> *
> FROM
> Product
> WHERE
> TabID = @.TabID
> ORDER BY
> @.Order
> GO
> but I get this message:
> Error 1008: The SELECT item identified by the ORDER BY number 1 contains a
> variable as part of the expression identifying a column position. Variable
s
> are only allowed when ordering by an expression referencing a column name.
> Is it possible to do what I want? What am I doing wrong?
> Thank you.|||Thanks! Your replies were absolutely efective.

Friday, February 24, 2012

"Key Column Information...."

Hi everybody!
I have the following problem: I have many tables in my database and for
some columns it happens that when I try to update them, I get the error
message, that the update doesn't work properly, because of "Key column
information insufficient or incorrect". This happens only for a few
columns in the table.
Example:
Table "tabProductColorPackage"
ID (INT, AutoSeed, Pkey)
Number (DECIMAL(18,2))
Unit (DECIMAL(18,2))
My VB-Code:
Recordset.Open "SELECT Unit FROM tabProductColorPackage WHERE ID=2"
Recordset.Fields("Unit") = 1
Recordset.Update
--> Works fine!
Recordset.Open "SELECT Number FROM tabProductColorPackage WHERE ID=2"
Recordset.Fields("Unit") = 1
Recordset.Update
--> Produces the error given in my description.
What the hell is going wrong here?
Thanks in advance,
BerndHi!
Sorry, the VB-Code that produces the error is as follows:
> Recordset.Open "SELECT Number FROM tabProductColorPackage WHERE ID=2"
> Recordset.Fields("Number") = 1
> Recordset.Update
Thanks,
Bernd

"Key Column Information...."

Hi everybody!
I have the following problem: I have many tables in my database and for
some columns it happens that when I try to update them, I get the error
message, that the update doesn't work properly, because of "Key column
information insufficient or incorrect". This happens only for a few
columns in the table.
Example:
Table "tabProductColorPackage"
ID (INT, AutoSeed, Pkey)
Number (DECIMAL(18,2))
Unit (DECIMAL(18,2))
My VB-Code:
Recordset.Open "SELECT Unit FROM tabProductColorPackage WHERE ID=2"
Recordset.Fields("Unit") = 1
Recordset.Update
--> Works fine!
Recordset.Open "SELECT Number FROM tabProductColorPackage WHERE ID=2"
Recordset.Fields("Unit") = 1
Recordset.Update
--> Produces the error given in my description.
What the hell is going wrong here?
Thanks in advance,
BerndHi!
Sorry, the VB-Code that produces the error is as follows:

> Recordset.Open "SELECT Number FROM tabProductColorPackage WHERE ID=2"
> Recordset.Fields("Number") = 1
> Recordset.Update
Thanks,
Bernd

Sunday, February 19, 2012

"Insufficient key column information for updating and refreshing"

"Insufficient key column information for updating and refreshing"
What does this message mean. All that I am trying to do is manually update
2 rows in one table with one join to another table with the updated values.
Thanks.
ArcherThis message means that SQL Server can determine which value you want to
update because is the relation is not that clear for him. That could be
caused if you want to update a joined table for common data which can be
changed in particular only one ROW. But the best thing would be if you could
send some DDL and the query to find your problem.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"bagman3rd" <bagman3rd@.discussions.microsoft.com> schrieb im Newsbeitrag
news:3EA65F99-EC00-4156-B1B1-1C1A0E52DAB9@.microsoft.com...
> "Insufficient key column information for updating and refreshing"
> What does this message mean. All that I am trying to do is manually
> update
> 2 rows in one table with one join to another table with the updated
> values.
> Thanks.
> Archer|||Hi,
See the KB :-
http://support.microsoft.com/defaul...kb;en-us;814893
Thanks
Hari
SQL Server MVP
"bagman3rd" <bagman3rd@.discussions.microsoft.com> wrote in message
news:3EA65F99-EC00-4156-B1B1-1C1A0E52DAB9@.microsoft.com...
> "Insufficient key column information for updating and refreshing"
> What does this message mean. All that I am trying to do is manually
> update
> 2 rows in one table with one join to another table with the updated
> values.
> Thanks.
> Archer|||It means that there is no primary key declared on the table
by which the row you want to update can be identified
uniquely. When you "view" a table, you can point to a
row by where it is on the screen, but for the update to
succeed, the row must be identified by the value of a
declared primary key, not where you see it on the screen.
Non-database programs, like Excel, keep track of data
by physical position (row number), but database systems
do not. What you see on the screen when you do a "manual
update" is not the actual data, but a result set, like a printout.
It's a dubious convenience of most database systems to
provide an interface whereby someone can change something
in a printout and have the change propogate back to the data.
An UPDATE statement is the best way to modify data,
and my guess is that you can't specify what you want to
update uniquely in a WHERE clause.
Steve Kass
Drew University
bagman3rd wrote:

>"Insufficient key column information for updating and refreshing"
>What does this message mean. All that I am trying to do is manually update
>2 rows in one table with one join to another table with the updated values.
>Thanks.
>Archer
>

"insert into" with text type - newbie

Hello,

When I try "Insert Into" with a text column value that's very long, I
only get a cropped version inserted (I know because when I
programmatically access the field, it's cropped-- I'm not just
assuming this from query manager). The text column has a default size
of small, however I don't understand why it is only inserting the
default amoutn instead of the whole string. I am using "Insert Into
table (blah, blah) values (blah, 'loooooooooooooooooooooooooooong
entry')", and programmatically running that command.

I'm stumped. Why is it inserting only part of the long entry value?"vavavoomy2" <vavavoomy2@.yahoo.com> wrote in message
news:c5e42899.0310280942.177d251c@.posting.google.c om...
> Hello,
> When I try "Insert Into" with a text column value that's very long, I
> only get a cropped version inserted (I know because when I
> programmatically access the field, it's cropped-- I'm not just
> assuming this from query manager). The text column has a default size
> of small, however I don't understand why it is only inserting the
> default amoutn instead of the whole string. I am using "Insert Into
> table (blah, blah) values (blah, 'loooooooooooooooooooooooooooong
> entry')", and programmatically running that command.
> I'm stumped. Why is it inserting only part of the long entry value?

What does a "default size of small" mean? Text columns in MSSQL don't have a
variable width, are you talking about a char/varchar column?

In any case, you should probably check if you have ANSI_WARNINGS set OFF in
the connection properties for your client. By default this is on (for OLE
DB/ODBC at least), and inserting data which would be truncated gives an
error. Setting it to off suppresses the error and allows the insert to
happen.

If that isn't the case, can you post your CREATE TABLE statement, and an
INSERT statement which reproduces the problem? Also, does the error happen
when you execute the INSERT manually in Query Analyzer or only
programmatically?

Simon|||"vavavoomy2" <vavavoomy2@.yahoo.com> wrote in message
news:c5e42899.0310280942.177d251c@.posting.google.c om...
> Hello,
> When I try "Insert Into" with a text column value that's very long, I
> only get a cropped version inserted (I know because when I
> programmatically access the field, it's cropped-- I'm not just
> assuming this from query manager). The text column has a default size
> of small, however I don't understand why it is only inserting the
> default amoutn instead of the whole string. I am using "Insert Into
> table (blah, blah) values (blah, 'loooooooooooooooooooooooooooong
> entry')", and programmatically running that command.
> I'm stumped. Why is it inserting only part of the long entry value?

What does a "default size of small" mean? Text columns in MSSQL don't have a
variable width, are you talking about a char/varchar column?

In any case, you should probably check if you have ANSI_WARNINGS set OFF in
the connection properties for your client. By default this is on (for OLE
DB/ODBC at least), and inserting data which would be truncated gives an
error. Setting it to off suppresses the error and allows the insert to
happen.

If that isn't the case, can you post your CREATE TABLE statement, and an
INSERT statement which reproduces the problem? Also, does the error happen
when you execute the INSERT manually in Query Analyzer or only
programmatically?

Simon

Thursday, February 16, 2012

"Ghost" primary key column

Hello,
I have a table 'customers', with 2 records:

SELECT * FROM customers;
customerID | customerName
------+--------
myFriend | myFriend's Name
test | testing user
(2 rows)

but when I'm asking about customerID column, I get the answer:

SELECT customerID FROM customers;
ERROR: column "customerid" does not exist

What happens? I'm using PostgreSQL 8.1.3>> What happens? I'm using PostgreSQL 8.1.3 <<

Why are you positng to a SQL Server Newsgroup? And why did you fail to
provide DDL, anyway?|||(chrisek@.poczta.neostrada.pl) writes:
> I have a table 'customers', with 2 records:
> SELECT * FROM customers;
> customerID | customerName
> ------+--------
> myFriend | myFriend's Name
> test | testing user
> (2 rows)
> but when I'm asking about customerID column, I get the answer:
> SELECT customerID FROM customers;
> ERROR: column "customerid" does not exist
> What happens? I'm using PostgreSQL 8.1.3

The interesting part is that your sample output has customerID, and
so has the your query that generates the error message. But the
message complains that "customerid" in all lower case is missing!

Either PostgreSQL is a very strange beast, or your actual query
used "customerid" and PostgreSQL is case-sensitive, just like
MS SQL Server may be depending on the collation. I will have to admit
that my bets are on the latter.

And, no, I don't mention MS SQL Server on a whim. This newsgroups
is devoted to MS SQL Server, and not very packed with people who
can assist you with PostgreSQL.

--
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|||"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1151263386.915461.288040@.p79g2000cwp.googlegr oups.com...
>>> What happens? I'm using PostgreSQL 8.1.3 <<
> Why are you positng to a SQL Server Newsgroup?

Who knows why people post non-SQL Server-related stuff to an MS SQL Server
newsgroup? It seems to happen an *awful* lot these days though.|||"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1151263386.915461.288040@.p79g2000cwp.googlegr oups.com...
> >> What happens? I'm using PostgreSQL 8.1.3 <<
> Why are you positng to a SQL Server Newsgroup? And why did you fail to
> provide DDL, anyway?

I suspect they're the same answer. Not knowing better.

In any case, I think Erland was able to at least try to help.

Monday, February 13, 2012

"Default bound to column

I am running a script against a couple of databases on my SQL Server 2000 Standard Edition Instance and I am getting the following in the results pane:

"Default bound to column" I have searched the MS Knowledge base and found a couple of vague references to this. Does anyone know why I might be getting this? the script 'seems' to run fine.. except for the funky error in the results pane. Script is attached. Thank you!!maybe no one has answered because zip files make people nervous (viruses). Just post the code using the tags. I know I am not opening your zip file.|||IIRC the sp_bindefault will give that message; just run one of them to confirm that.

ALSO never zip up a SQL script as a DOC file and think you are going to get an answer.

Change it to a text file and then only if it is very large zip it up.

doc files are the most common file used to tranmit virii to other people followed by zip files so very few people word open your file.

I have both zip & doc files set to open with non-MS software so I should be safe but I almost did not open the doc.

Tim S

Saturday, February 11, 2012

"CREATE TABLE" for files *.dbf with a custom float column

How to create dbase file based on SQL-92 which have a FLOAT column like
float(14,2):
=> xxxxxxxxxxxxxx,xx <=
Thanks in advance,
PatriceN(14,2)
"news.microsoft.com" <reprotechnic@.wanadoo.fr> escribi en el mensaje
news:u37grkt#DHA.2072@.TK2MSFTNGP11.phx.gbl...
> How to create dbase file based on SQL-92 which have a FLOAT column like
> float(14,2):
> => xxxxxxxxxxxxxx,xx <=
> Thanks in advance,
> Patrice
>|||this solution doesn't run. it makes a float column of (20,4).
With more precision, i test this with odbc.net from Framework.NET v1.1
"Luis Camacho" <luibrac@.yahoo.com.ar> a crit dans le message de
news:%23VMvv5K$DHA.1036@.TK2MSFTNGP10.phx.gbl...
> N(14,2)
> "news.microsoft.com" <reprotechnic@.wanadoo.fr> escribi en el mensaje
> news:u37grkt#DHA.2072@.TK2MSFTNGP11.phx.gbl...
>|||N(14,2): This does not work and gives a syntax error on command.
AndreB.
"Luis Camacho" <luibrac@.yahoo.com.ar> a crit dans le message de
news:%23VMvv5K$DHA.1036@.TK2MSFTNGP10.phx.gbl...
> N(14,2)
> "news.microsoft.com" <reprotechnic@.wanadoo.fr> escribi en el mensaje
> news:u37grkt#DHA.2072@.TK2MSFTNGP11.phx.gbl...
>