Showing posts with label ouput. Show all posts
Showing posts with label ouput. Show all posts

Tuesday, March 20, 2012

ouput of difference in two Strings

Hi, I need an ouput of difference in two Strings

Declare @.StringA varchar(100), @.StringB varchar(100)

@.StringA = 'A,B,C'
@.StringB = 'A,C,C'

The values are seperated in the strings by ','

Since B value in first string changed to C value in the second string
I want to return the difference between the two strings as 'B,C'

Can anyone help me with this.

ThanksWell, you could write a user-defined function that accepts two strings and steps through them each one character at a time to detect differences. But this is a really goofy setup. Can't you normalize your data? Storing data in comma-delimited strings is right up there at the top of the list of DBA cardinal sins. In standard 3rd-normal form this request would be very easy.|||Plus depending on what you mean by "difference", your solution could also be different.

A comma-delimited list is not really a "string" that you can detect differences in...I mean, it is, but not the way you are using it (as I understand your question, anyway).

I mean, is "A,B,C" the same as "B,C,A" or "C,B,A"? Or are those supposed to be "different" strings?

There are quite a few procedures, functions, and other code examples on the 'net and in the dbforums archives about sucking elements out of CSV lists...but then you still have to deal with the now free-floating elements (again, does order matter?)

Yeah, like The Blind One says...normalize your data...or at least maybe create a temp table from the strings? Naaahhh...normalize your data.

Go ahead, we'll wait ;)

Wednesday, March 7, 2012

OSQL Ouput Formatting.

Hi,
When I execute a query in OSQL using Query Analyser the output is not well
formatted.
Sample Query is given below.
Can someone suggest me a way to get good readable format in QA.
Thanks in advance.
-Kumar.
--***--
SELECT TOP 3 * FROM pubs..authors
--Using Command Prompt:
--osql -E -Q "SELECT TOP 3 * FROM authors" -d pubs
--Using Query Analyser:
DECLARE @.vcSQLCmd VARCHAR(1000)
SET @.vcSQLCmd = 'osql -E -Q "SELECT * FROM authors" -d pubs'
EXEC master..xp_cmdShell @.vcSQLCmd
--***--
--SeequellWhy are you using osql, if you want the results in QA? Why not use it
directly?
Anith|||Let me give more details...
I have few script files and those need to be run against few Db Servers/DBs.
I would like to run these scripts from my computer by just changing
Server/Db name.
--Seequell
"Anith Sen" wrote:

> Why are you using osql, if you want the results in QA? Why not use it
> directly?
> --
> Anith
>
>|||>> I have few script files and those need to be run against few Db
OK, with osql there results are formatted to display at the command prompt.
And there is not much you can do to change it in Query Analyzer.
In you case, if QA formatting is important consider using 4 part naming (
server.database.owner.object ) or a pass-though query ( like OPENQUERY,
OPENROWSET etc. ) to access data from external servers. Details about linked
servers ( 4 part naming ) as well as using distributed queries are well
documented in SQL Server Books Online.
Anith|||Thanks a lot Anith.
--Seequell
"Anith Sen" wrote:

> OK, with osql there results are formatted to display at the command prompt
.
> And there is not much you can do to change it in Query Analyzer.
> In you case, if QA formatting is important consider using 4 part naming (
> server.database.owner.object ) or a pass-though query ( like OPENQUERY,
> OPENROWSET etc. ) to access data from external servers. Details about link
ed
> servers ( 4 part naming ) as well as using distributed queries are well
> documented in SQL Server Books Online.
> --
> Anith
>
>|||Hi Anith,
I found a -w switch in OSQL for changing the width of the output, I think.
I am exploring more on it. Thanks.
--Seequell
"Seequell" wrote:
> Thanks a lot Anith.
> --Seequell
>
> "Anith Sen" wrote:
>