Wednesday, March 7, 2012
re-arrange name data
First Middle Last
into
Last, First Middle in the outputted .csv file
thanks in advance.
-csubstring(fld,len(fld) - charindex(' ',reverse(fld)),len(fld))
+ ', ' + left(fld,len(fld)-charindex(' ',reverse(fld)))
The numbers will be a bit wrong but you can fix that.
Really need help w/ connection manager problem in SSIS
Hello,
I am attempting to set up a Connection Manager for a Flat File Source.
Data in my flat file is like this, for example:
"038188306","03/02/2007"
"038C88328","9A9990846","INFY-SW ","L","Z98ZVL97R","2006-06-02"
Row 1 has two columns, Row 2 has six columns (as delimited by the double quotes).
Format: Delimited
Text Qualifer: {""}
Header Row Delimiter: {CR}{LF}
But when I click on the Columns button, it only shows 2 columns. For example, it shows the first row correctly, but Row 2 shows as:
Column 1
"038C88328"
Column 2
"9A9990846","INFY-SW ","L","Z98ZVL97R","2006-06-02"
which is NOT what I want.
I really need help here.
THANKS
Nevermind, figured it out :-)
Need to skip first row
|||Hey K108,
I just wanted to know how did yo figured ti out.
Thanks,
Vikt
|||The answer is, all the rows in the text file must have the exact same number of columns. In my text file, the first row is garbage data with only 2 columns. So I just needed to select the option to skip 1 row.Really need help w/ connection manager problem in SSIS
Hello,
I am attempting to set up a Connection Manager for a Flat File Source.
Data in my flat file is like this, for example:
"038188306","03/02/2007"
"038C88328","9A9990846","INFY-SW ","L","Z98ZVL97R","2006-06-02"
Row 1 has two columns, Row 2 has six columns (as delimited by the double quotes).
Format: Delimited
Text Qualifer: {""}
Header Row Delimiter: {CR}{LF}
But when I click on the Columns button, it only shows 2 columns. For example, it shows the first row correctly, but Row 2 shows as:
Column 1
"038C88328"
Column 2
"9A9990846","INFY-SW ","L","Z98ZVL97R","2006-06-02"
which is NOT what I want.
I really need help here.
THANKS
Nevermind, figured it out :-)
Need to skip first row
|||Hey K108,
I just wanted to know how did yo figured ti out.
Thanks,
Vikt
|||The answer is, all the rows in the text file must have the exact same number of columns. In my text file, the first row is garbage data with only 2 columns. So I just needed to select the option to skip 1 row.Saturday, February 25, 2012
Really complex query that has me stymied
complex way, and I can't figure a way around it. Because of the architecture
in use, it has to be done in a single query, without using a stored
procedure. This is a simplified version of what I'm doing:
Let's say I have two tables, each with four columns, named A, B, C and D:
Table 1
A,B,C,D
1,2,3,5
3,5,7,9
3,9,2,6
3,6,7,1
9,8,3,0
2,5,8,1
Table 2
A,B,C,D
5,3,2,3
4,8,7,1
3,5,7,2
1,4,5,6
8,9,3,2
2,6,2,2
Each of the tables has thousands of records. I need a query that does this:
For each row in table 1, look up the values in table 2. If a row can be
found in table 2 whose columns A, B and C match columns A, B and C in table
1, and whose column D equals 2, then return the row from table 1. Do not
return a row unless all three columns A, B and C match, and Table2.D equals
2.
Using this rule on the table values above, it should be returning only the
row "3,5,7,9" from Table 1 because there is only one row in Table 2 that has
columns A,B,C,D equal to "3,5,7,2"
Here's what I'm trying now:
SELECT * FROM Table1
WHERE
Table1.A IN (SELECT DISTINCT(A) FROM Table2 WHERE Table2.D = 2)
AND
Table1.B IN (SELECT DISTINCT(B) FROM Table2 WHERE Table2.D = 2)
AND
Table1.C IN (SELECT DISTINCT(C) FROM Table2 WHERE Table2.D = 2)
This returns 3,5,7,9, 3,9,2,6 and 3,6,7,1 from Table 1, when it should only
be returning 3,5,7,9. It does this because column A matches (3), Column B
matches multiple records in Table 2 with a Table2.D=2, and so does Column C.
Even though I am specifying AND for the three columns, it is actually acting
as an OR, because each SELECT DISTINCT is separate, and does not take into
consideration the other SELECTs. The first SELECT DISTINCT pulls a result
set, and Column A is compared against it. The second SELECT DISTINCT pulls a
different result set, and Column B is compared against it. And so on. This
results in an additive comparison. What I need, in effect, is for the SELECT
DISTINCT(B) to be more like "Take the SELECT DISTINCT(A) result set and pare
it down further using the SELECT DISTINCT(B) values". Then The SELECT
DISTINCT(C) needs to be more like "Take the SELECT DISTINCT(B) result set
and pare it down even further using the SELECT DISTINCT(C) values".
I hope this makes sense, and that someone can see what I'm missing. I've
spent hours trying to figure out a way of doing this, without success.Scott,
Try this:
SELECT A, B, C, D
FROM [Table 1] AS T1
WHERE EXISTS (
SELECT * FROM [Table 2] AS T2
WHERE T2.A = T1.A
AND T2.B = T1.B
AND T2.C = T1.C
AND T2.D = 2
)
or
SELECT T1.A, T1.B, T1.C, T1.D
FROM [Table 1] AS T1
JOIN [Table 2] AS T2
ON T2.A = T1.A
AND T2.B = T1.B
AND T2.C = T1.C
WHERE
T2.D = 2
The latter query will return duplicate rows, so it could need
DISTINCT. Use whichever is faster (hopefully at least one
has no typos).
Steve Kass
Drew University
Scott MacLean wrote:
>I'm attempting to write a query that pulls data from two tables in a really
>complex way, and I can't figure a way around it. Because of the architectur
e
>in use, it has to be done in a single query, without using a stored
>procedure. This is a simplified version of what I'm doing:
>Let's say I have two tables, each with four columns, named A, B, C and D:
>Table 1
>A,B,C,D
>1,2,3,5
>3,5,7,9
>3,9,2,6
>3,6,7,1
>9,8,3,0
>2,5,8,1
>Table 2
>A,B,C,D
>5,3,2,3
>4,8,7,1
>3,5,7,2
>1,4,5,6
>8,9,3,2
>2,6,2,2
>Each of the tables has thousands of records. I need a query that does this:
>For each row in table 1, look up the values in table 2. If a row can be
>found in table 2 whose columns A, B and C match columns A, B and C in table
>1, and whose column D equals 2, then return the row from table 1. Do not
>return a row unless all three columns A, B and C match, and Table2.D equals
>2.
>Using this rule on the table values above, it should be returning only the
>row "3,5,7,9" from Table 1 because there is only one row in Table 2 that ha
s
>columns A,B,C,D equal to "3,5,7,2"
>Here's what I'm trying now:
>SELECT * FROM Table1
>WHERE
> Table1.A IN (SELECT DISTINCT(A) FROM Table2 WHERE Table2.D = 2)
>AND
> Table1.B IN (SELECT DISTINCT(B) FROM Table2 WHERE Table2.D = 2)
>AND
> Table1.C IN (SELECT DISTINCT(C) FROM Table2 WHERE Table2.D = 2)
>This returns 3,5,7,9, 3,9,2,6 and 3,6,7,1 from Table 1, when it should only
>be returning 3,5,7,9. It does this because column A matches (3), Column B
>matches multiple records in Table 2 with a Table2.D=2, and so does Column C
.
>Even though I am specifying AND for the three columns, it is actually actin
g
>as an OR, because each SELECT DISTINCT is separate, and does not take into
>consideration the other SELECTs. The first SELECT DISTINCT pulls a result
>set, and Column A is compared against it. The second SELECT DISTINCT pulls
a
>different result set, and Column B is compared against it. And so on. This
>results in an additive comparison. What I need, in effect, is for the SELEC
T
>DISTINCT(B) to be more like "Take the SELECT DISTINCT(A) result set and par
e
>it down further using the SELECT DISTINCT(B) values". Then The SELECT
>DISTINCT(C) needs to be more like "Take the SELECT DISTINCT(B) result set
>and pare it down even further using the SELECT DISTINCT(C) values".
>I hope this makes sense, and that someone can see what I'm missing. I've
>spent hours trying to figure out a way of doing this, without success.
>
>|||Hello, Scott
This should do the job:
SELECT * FROM Table1 T1
WHERE EXISTS (
SELECT * FROM Table2 T2
WHERE T1.A=T2.A AND T1.B=T2.B AND T1.C=T2.C
AND T2.D=2
)
Razvan|||Thanks Steve and Razvan, this did the trick. Once I saw this I thought; "of
COURSE" (hand slap on forehead).
Thanks again.
"Razvan Socol" <rsocol@.gmail.com> wrote in message
news:1110347824.072514.140200@.z14g2000cwz.googlegroups.com...
> Hello, Scott
> This should do the job:
> SELECT * FROM Table1 T1
> WHERE EXISTS (
> SELECT * FROM Table2 T2
> WHERE T1.A=T2.A AND T1.B=T2.B AND T1.C=T2.C
> AND T2.D=2
> )
> Razvan
>
Reality of remote connection
application. I am attempting to login using the administrator account that
has been added to the SQL server database and given all the roles. The auth
mode is mixed (it was windows, but I changed it to mixed after reading
around).
So, as a test I try to get Visual Studio 2003 Pro to connect to the
database, figuring it will at least do the connection string correctly. I put
in the IP of the server and the username/password into the new connection
dialog and hit Test Connection.
I get:
Test connection failed because of an error in initialising provider. Login
failed for user 'Administrator'.
So basically, I would like to know:
a) Is this possible? Should I instead be writing a server application that I
connect to on the SQL server machine that connects to SQL Server on my behalf?
b) Is there something simple I am missing? I would prefer to make a direct
connection to SQL Server if possible.
Thankyou for reading. Any help would be appreciated.
Hi
That will work, but either your username 'Administrator' or password are
wrong.
Check those and try again.
Cheers
Mike
"BLiTZWiNG" wrote:
> I'm trying to connect to my sql database across the internet from a C#
> application. I am attempting to login using the administrator account that
> has been added to the SQL server database and given all the roles. The auth
> mode is mixed (it was windows, but I changed it to mixed after reading
> around).
> So, as a test I try to get Visual Studio 2003 Pro to connect to the
> database, figuring it will at least do the connection string correctly. I put
> in the IP of the server and the username/password into the new connection
> dialog and hit Test Connection.
> I get:
> Test connection failed because of an error in initialising provider. Login
> failed for user 'Administrator'.
> So basically, I would like to know:
> a) Is this possible? Should I instead be writing a server application that I
> connect to on the SQL server machine that connects to SQL Server on my behalf?
> b) Is there something simple I am missing? I would prefer to make a direct
> connection to SQL Server if possible.
> Thankyou for reading. Any help would be appreciated.
|||Thanks Mike, I'm happy to know it can work. I even realised that I was inside
the same subnet (live proxy ip was same sub as server) so it shouldn't have
even been domain issue.
I know I have the password correct because I was remote desktoped to the
server as admin and playing with the enterprise manager. My C# / ASP.NET app
running on the same server can interact with my database, I just can't access
it from a different machine directly. The only thing I can think of is that
maybe our proxy server is not behaving, in which case I'm going to install
SQL Server on an internal server so I don't have proxy issues and try it that
way.
Thanks for your help.
"Mike Epprecht (SQL MVP)" wrote:
[vbcol=seagreen]
> Hi
> That will work, but either your username 'Administrator' or password are
> wrong.
> Check those and try again.
> Cheers
> Mike
> "BLiTZWiNG" wrote:
|||Well I got it to work. It seems that you cannot log in with a user that has
an assosciated with a windows active directory account even though the server
is in mixed mode authentication. If I log in as an SQL server user only, like
sa, it logs in fine.
Odd.
"BLiTZWiNG" wrote:
[vbcol=seagreen]
> Thanks Mike, I'm happy to know it can work. I even realised that I was inside
> the same subnet (live proxy ip was same sub as server) so it shouldn't have
> even been domain issue.
> I know I have the password correct because I was remote desktoped to the
> server as admin and playing with the enterprise manager. My C# / ASP.NET app
> running on the same server can interact with my database, I just can't access
> it from a different machine directly. The only thing I can think of is that
> maybe our proxy server is not behaving, in which case I'm going to install
> SQL Server on an internal server so I don't have proxy issues and try it that
> way.
> Thanks for your help.
> "Mike Epprecht (SQL MVP)" wrote:
|||it could possible depending on your connection-layer
(ADO,...)
that you need to set a property Use Trusted Connection to
False
>--Original Message--
>Well I got it to work. It seems that you cannot log in
with a user that has
>an assosciated with a windows active directory account
even though the server
>is in mixed mode authentication. If I log in as an SQL
server user only, like[vbcol=seagreen]
>sa, it logs in fine.
>Odd.
>"BLiTZWiNG" wrote:
realised that I was inside[vbcol=seagreen]
so it shouldn't have[vbcol=seagreen]
desktoped to the[vbcol=seagreen]
manager. My C# / ASP.NET app[vbcol=seagreen]
database, I just can't access[vbcol=seagreen]
can think of is that[vbcol=seagreen]
I'm going to install[vbcol=seagreen]
issues and try it that[vbcol=seagreen]
username 'Administrator' or password are[vbcol=seagreen]
internet from a C#[vbcol=seagreen]
administrator account that[vbcol=seagreen]
all the roles. The auth[vbcol=seagreen]
mixed after reading[vbcol=seagreen]
to connect to the[vbcol=seagreen]
connection string correctly. I put[vbcol=seagreen]
into the new connection[vbcol=seagreen]
initialising provider. Login[vbcol=seagreen]
server application that I[vbcol=seagreen]
to SQL Server on my behalf?[vbcol=seagreen]
prefer to make a direct
>.
>
|||Tried using trusted connection, but I'm not a member of the domain (as the
client using the release software will not be either).
I can live with it being in SQL native mode because it works, but I hate not
knowing why these things don't work, or if they ever can. Does my workstation
have to be a member of the domain to be able to authenticate using a windows
AD account?
"gandalf" wrote:
> it could possible depending on your connection-layer
> (ADO,...)
> that you need to set a property Use Trusted Connection to
> False
>
> with a user that has
> even though the server
> server user only, like
> realised that I was inside
> so it shouldn't have
> desktoped to the
> manager. My C# / ASP.NET app
> database, I just can't access
> can think of is that
> I'm going to install
> issues and try it that
> username 'Administrator' or password are
> internet from a C#
> administrator account that
> all the roles. The auth
> mixed after reading
> to connect to the
> connection string correctly. I put
> into the new connection
> initialising provider. Login
> server application that I
> to SQL Server on my behalf?
> prefer to make a direct
>