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

Friday, March 30, 2012

one more import issue

I am importing a text file with '~' column delimiter and my text has in the file has some format.If i import the data into the sql table all the text is appearing in one line by missing the formart.

(here is the sample data.
empid~empname~emp_txt*
1~jjjj~kkkgkhfdhg
hhhghg
hoghodshgohdsoiahgfhoghojhqgh*
2~3333~gdskhkgjh
ghfdgh
fkjhbdskjhkghdghah*

)

IF i import the above data into a table with emp_txt as text data type
i am getting
kkkgkhfdhg
hhhghg
hoghodshgohdsoiahgfhoghojhqgh
all in one row like:kkkgkhfdhg hhhghg hoghodshgohdsoiahgfhoghojhqgh.But i should get it same as in the notepad.
for that i have changed the datatype of the emp_text column as image in my database.
But when i change the datatype my DTS is giving the following error:

Error at Destination for Row number 1. Errors encountered so far in this task: 1.
Insert error,Column3('emp_text',DBTYPE_BYTES),status 2: Error converting value.
Invalid character value for cast specification.In the format file also specify asterisk (*) as a row separator.

One for the advanced programmers!

I have a string column but I need to check if it contains any numeric
data ( in a WHERE Clause).
I did the following without any success
WHERE CONVERT(int,geocode) > 0
Gives an error as soon as it finds any non-numeric data.
Thanks> I have a string column but I need to check if it contains any numeric
> data ( in a WHERE Clause).
Try:
WHERE geocode LIKE '%[0-9]%'
Hope this helps.
Dan Guzman
SQL Server MVP
"S Chapman" <s_chapman47@.hotmail.co.uk> wrote in message
news:1140448043.080918.304840@.g47g2000cwa.googlegroups.com...
> I have a string column but I need to check if it contains any numeric
> data ( in a WHERE Clause).
> I did the following without any success
> WHERE CONVERT(int,geocode) > 0
> Gives an error as soon as it finds any non-numeric data.
> Thanks
>|||S Chapman wrote:
> I have a string column but I need to check if it contains any numeric
> data ( in a WHERE Clause).
> I did the following without any success
> WHERE CONVERT(int,geocode) > 0
> Gives an error as soon as it finds any non-numeric data.
> Thanks
WHERE geocode NOT LIKE '%[^0-9]%'
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Hi
CREATE TABLE Sometable (currencyvalues VARCHAR(20) PRIMARY KEY)
INSERT INTO Sometable VALUES ('xnl 23.15')
INSERT INTO Sometable VALUES ('xnl')
INSERT INTO Sometable VALUES ('-23.15')
INSERT INTO Sometable VALUES ('muu')
SELECT * FROM Sometable WHERE currencyvalues LIKE '%[0-9]%'
--or
SELECT * FROM Sometable WHERE PATINDEX('%[0-9]%',currencyvalues)>0
Be aware that SQL Server will not probably use an index on the columnn ( if
you have one)
"S Chapman" <s_chapman47@.hotmail.co.uk> wrote in message
news:1140448043.080918.304840@.g47g2000cwa.googlegroups.com...
> I have a string column but I need to check if it contains any numeric
> data ( in a WHERE Clause).
> I did the following without any success
> WHERE CONVERT(int,geocode) > 0
> Gives an error as soon as it finds any non-numeric data.
> Thanks
>|||S wrote on 20 Feb 2006 07:07:23 -0800:

> I have a string column but I need to check if it contains any numeric
> data ( in a WHERE Clause).
> I did the following without any success
> WHERE CONVERT(int,geocode) > 0
> Gives an error as soon as it finds any non-numeric data.
Are you look for numbers within the column, or a column that is just a
number? If the latter then you can using this:
WHERE ISNUMERIC(geocode) = 1
Dan|||Daniel
It will resturns wrong result as well as ISNUMERIC function is inaccurate
http://www.aspfaq.com/show.asp?id=2390
INSERT INTO Sometable VALUES ('xnl 23.15')
INSERT INTO Sometable VALUES ('.')
SELECT * FROM Sometable WHERE ISNUMERIC(currencyvalues)=1
"Daniel Crichton" <msnews@.worldofspack.co.uk> wrote in message
news:%237y6iGjNGHA.740@.TK2MSFTNGP12.phx.gbl...
>S wrote on 20 Feb 2006 07:07:23 -0800:
>
> Are you look for numbers within the column, or a column that is just a
> number? If the latter then you can using this:
> WHERE ISNUMERIC(geocode) = 1
>
> Dan
>

Wednesday, March 28, 2012

one control loop with Substring to correct first normal column violation

given a table from an excel spreadsheet that contains a column that violates
first normal ;
Area Code TimeZone
787/939 4
212/646/718/917 5
I would like to create one procedure that loops through n possible values of
the area codes and creates a separate row for each value.
The Substring(s) below would have to start from positions
1,5,9,13,17,21,25,29 to capture the 3 character codes.
Right now I am manually creating each table with separate Substring
select/inserts with a union of all the tables and a select distinct.
The 65,000 rows of the original table end up deduped into about 245 rows of
distinct area codes per time zones.
Here are the first two sets of queries (there are 7 total) followed by the
consolidation with UNION ALL
-- create row with only first area code of '/' delimited values
CREATE TABLE first_areacode
(AreaCode varchar(50),
TimeZone varchar(50))
INSERT INTO first_areacode
(AreaCode, TimeZone)
select SUBSTRING(AreaCode, 1, 3) AS AreaCode,TimeZone
from AreaCodeTimeZone
-- create row with only second area code of '/' delimited values
CREATE TABLE second_areacode
(AreaCode varchar(50),
TimeZone varchar(50))
INSERT INTO second_areacode
(AreaCode, TimeZone)
select SUBSTRING(AreaCode, 5, 3) AS AreaCode,TimeZone
from AreaCodeTimeZone
insert into combined_areacode
SELECT * FROM first_areacode
UNION ALL
SELECT * FROM second_areacode
UNION ALL
SELECT * FROM third_areacode
UNION ALL
etc.
.
Thank you for ideas to help automate this,
-Greghazz (hazz@.sonic.net) writes:
> I would like to create one procedure that loops through n possible
> values of the area codes and creates a separate row for each value. The
> Substring(s) below would have to start from positions
> 1,5,9,13,17,21,25,29 to capture the 3 character codes. Right now I am
> manually creating each table with separate Substring select/inserts with
> a union of all the tables and a select distinct. The 65,000 rows of the
> original table end up deduped into about 245 rows of distinct area codes
> per time zones.
> Here are the first two sets of queries (there are 7 total) followed by the
> consolidation with UNION ALL
> -- create row with only first area code of '/' delimited values
> CREATE TABLE first_areacode
> (AreaCode varchar(50),
> TimeZone varchar(50))
> INSERT INTO first_areacode
> (AreaCode, TimeZone)
> select SUBSTRING(AreaCode, 1, 3) AS AreaCode,TimeZone
> from AreaCodeTimeZone
As long as you can rely on that the area codes are exact three
characters, no extra spaces etc, this could work:
SELECT substring(AreaCode, n, 3), TimeZone
FROM tbl
CROSS JOIN (SELECT n = 1 UNION ALL SELECT 5 UNION ALL SELECT 9 UNION ALL
SELECT 13 UNION ALL SELECT 17 UNION ALL SELECT 21 UNION ALL
..) AS n
WHERE len(AreaCode) <= n
By the way, which version of SQL Server are you using?
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|||SQL 2005.
Thank you Erland !
-Greg
"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns977F34D4AFD2Yazorman@.127.0.0.1...
> hazz (hazz@.sonic.net) writes:
> As long as you can rely on that the area codes are exact three
> characters, no extra spaces etc, this could work:
> SELECT substring(AreaCode, n, 3), TimeZone
> FROM tbl
> CROSS JOIN (SELECT n = 1 UNION ALL SELECT 5 UNION ALL SELECT 9 UNION
> ALL
> SELECT 13 UNION ALL SELECT 17 UNION ALL SELECT 21 UNION ALL
> ...) AS n
> WHERE len(AreaCode) <= n
> By the way, which version of SQL Server are you using?
> --
> 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|||When I used this, the AreaCode column was blank although the TimeZone column
was populated.
I just reposted this with working sql that I would still like to condense
into an algorithm. Thanks, -Greg

> SELECT substring(AreaCode, n, 3), TimeZone
> FROM tbl
> CROSS JOIN (SELECT n = 1 UNION ALL SELECT 5 UNION ALL SELECT 9 UNION
> ALL
> SELECT 13 UNION ALL SELECT 17 UNION ALL SELECT 21 UNION ALL
> ...) AS n
> WHERE len(AreaCode) <= n

One column missing from datasets even after refresh?

My report's data source is a stored procedure which takes 4 parameters. If I execute the sp from the data tab it returns the correct data and columns; but if I right click the Report Datasets from the Datasets view and click on refresh I'm always missing one column. Is this related to the way the sp was written? Anybody had same expericence before? Thanks!

I have.

One thing you can do is check for a matching .rdl.data file and blow that away, see if next data pull rewrites the cached data.

Another thing you can probably do is just add it in manually. Rightclick on the *name* of the dataset (underneath the Report DataSets node in the Datasets window) and choose "Add..."

>L<

|||

Thanks for the help! The first method doesn't work. Even if I add a new report from scratch, the available fields are missing that column if I put the sp in the query builder from report build wizard.

Rightclick on the name of the dataset and add the missing column works, but after I deploy the report and go view the report from brower, I got the following message:

An error has occurred during report processing.

  • Query execution failed for data set 'RegionalLevelByWeek'.

  • For more information about this error navigate to the report server on the local server machine, or enable remote errors
  • |||Hmm. I think the first method doesn't work if you have a (usually generated) schema file associated

    with the data -- I'm not looking at reports right now, so I could be wrong) -- you might have to "refresh" that file as well.

    On the second one, do you have to re-deploy the datasource to the server or something? (remember it's "don't overwrite datasources during deploy" by default) Same is true with default values of params -- given your situation as you put it in this message, that might well be involved.

    Now that I look at what you're saying here though... As far as your current thing with the two SP's, you could just put a dummy column into the first result set, couldn't you? The important thing to remember is that there is going to be *one* set of columns associated with that report, never two, so if your proc can return differently based on a param you pretty much have to make them match.

    I'm sorry I can't do a worked example right now, it's always *something* find-able though...

    >L<

    sql
  • one column DISTINCT on 2 Tables

    hello I am trying to get a distinct on one column and 2 tables but it doesnt work

    Table1
    ID_Table1
    Name1
    Number1

    Table2
    ID_Table2
    ID_Table1
    Name2

    I want to get : ID_Table1, DISTINCT(Name1), Name2
    WHERE Name1 LIKE 'A%'

    how can I do it ?

    thank youDISTINCT is not a function

    does your query join these tables?

    could you show your actual query please?|||yes of course the 2 tables are JOIN by Table1.ID_Table1 AND Table2.ID_Table1|||and you want one result row per value of Name1, correct?

    okay, here is one way --select Table1.Name1
    , min(Table1.ID_Table1)
    , max(Table2.Name2)
    from Table1
    inner
    join Table2
    on Table2.ID_Table1 = Table1.ID_Table1
    where Table1.Name1 like 'A%'
    group
    by Table1.Name1|||it works fine !

    thanks again !

    one column causing duplicate rows - wrong join used?

    Hi,
    Consider the following result set:
    PNID PN_NUMBER Date1 Date2 Status PN_Na
    me
    ========================================
    ========================
    27 2051 08 Sep 1941 NULL Received NULL
    28 2143 01 Jan 1945 NULL Accepted NULL
    28 2143 01 Jan 1945 NULL Accepted R Anderson
    29 2151 NULL NULL Accepted NULL
    29 2151 NULL NULL Accepted W Yarwood
    30 1579 17 Nov 1925 NULL Received NULL
    31 4133 08 Feb 2002 NULL Accepted Mrs L Smith
    Here is the sql that returns the above:
    SELECT
    DISTINCT(PNP.PNID) AS 'PN_ID',
    PNP.PNNumber AS 'PN_NUMBER',
    CONVERT(VARCHAR(15), PNP.PNDate, 106) AS 'Date1',
    CONVERT(VARCHAR(15), PNP.InspectionDate, 106) AS 'Date2',
    PNP.PNStatus AS 'Status',
    BB.Name AS 'PN_NAME',
    FROM
    tblPNProperties PNP
    LEFT JOIN tblBusinessBoard BB
    ON PNP.PNID = BB.PNID
    My desired resultset would be to have pnids 28 and 29 to be unique,
    however because I am
    selecting PN_Name it causes the rows to have duplicates. How would I be
    able to obtain my desired resultset? (see below) Is my join correct?
    PNID PN_NUMBER Date1 Date2 Status PN_Na
    me
    ========================================
    ========================
    27 2051 08 Sep 1941 NULL Received NULL
    28 2143 01 Jan 1945 NULL Accepted R Anderson
    29 2151 NULL NULL Accepted W Yarwood
    30 1579 17 Nov 1925 NULL Received NULL
    31 4133 08 Feb 2002 NULL Accepted Mrs L Smith
    Any ideas?
    Thanks
    qhChange the LEFT JOIN to a JOIN.
    Tom
    ----
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
    SQL Server MVP
    Columnist, SQL Server Professional
    Toronto, ON Canada
    www.pinpub.com
    .
    "Quackhandle" <quackhandle1975@.yahoo.co.uk> wrote in message
    news:1133522905.310939.208490@.g49g2000cwa.googlegroups.com...
    Hi,
    Consider the following result set:
    PNID PN_NUMBER Date1 Date2 Status PN_Name
    ========================================
    ========================
    27 2051 08 Sep 1941 NULL Received NULL
    28 2143 01 Jan 1945 NULL Accepted NULL
    28 2143 01 Jan 1945 NULL Accepted R Anderson
    29 2151 NULL NULL Accepted NULL
    29 2151 NULL NULL Accepted W Yarwood
    30 1579 17 Nov 1925 NULL Received NULL
    31 4133 08 Feb 2002 NULL Accepted Mrs L Smith
    Here is the sql that returns the above:
    SELECT
    DISTINCT(PNP.PNID) AS 'PN_ID',
    PNP.PNNumber AS 'PN_NUMBER',
    CONVERT(VARCHAR(15), PNP.PNDate, 106) AS 'Date1',
    CONVERT(VARCHAR(15), PNP.InspectionDate, 106) AS 'Date2',
    PNP.PNStatus AS 'Status',
    BB.Name AS 'PN_NAME',
    FROM
    tblPNProperties PNP
    LEFT JOIN tblBusinessBoard BB
    ON PNP.PNID = BB.PNID
    My desired resultset would be to have pnids 28 and 29 to be unique,
    however because I am
    selecting PN_Name it causes the rows to have duplicates. How would I be
    able to obtain my desired resultset? (see below) Is my join correct?
    PNID PN_NUMBER Date1 Date2 Status PN_Name
    ========================================
    ========================
    27 2051 08 Sep 1941 NULL Received NULL
    28 2143 01 Jan 1945 NULL Accepted R Anderson
    29 2151 NULL NULL Accepted W Yarwood
    30 1579 17 Nov 1925 NULL Received NULL
    31 4133 08 Feb 2002 NULL Accepted Mrs L Smith
    Any ideas?
    Thanks
    qh|||Follow-up: If that doesn't fix it, could you please post your DDL for the
    two tables + INSERT's of the sample data? We may have to change your query
    further.
    Tom
    ----
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
    SQL Server MVP
    Columnist, SQL Server Professional
    Toronto, ON Canada
    www.pinpub.com
    .
    "Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message
    news:uTb$rXz9FHA.916@.TK2MSFTNGP10.phx.gbl...
    Change the LEFT JOIN to a JOIN.
    Tom
    ----
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
    SQL Server MVP
    Columnist, SQL Server Professional
    Toronto, ON Canada
    www.pinpub.com
    .
    "Quackhandle" <quackhandle1975@.yahoo.co.uk> wrote in message
    news:1133522905.310939.208490@.g49g2000cwa.googlegroups.com...
    Hi,
    Consider the following result set:
    PNID PN_NUMBER Date1 Date2 Status PN_Name
    ========================================
    ========================
    27 2051 08 Sep 1941 NULL Received NULL
    28 2143 01 Jan 1945 NULL Accepted NULL
    28 2143 01 Jan 1945 NULL Accepted R Anderson
    29 2151 NULL NULL Accepted NULL
    29 2151 NULL NULL Accepted W Yarwood
    30 1579 17 Nov 1925 NULL Received NULL
    31 4133 08 Feb 2002 NULL Accepted Mrs L Smith
    Here is the sql that returns the above:
    SELECT
    DISTINCT(PNP.PNID) AS 'PN_ID',
    PNP.PNNumber AS 'PN_NUMBER',
    CONVERT(VARCHAR(15), PNP.PNDate, 106) AS 'Date1',
    CONVERT(VARCHAR(15), PNP.InspectionDate, 106) AS 'Date2',
    PNP.PNStatus AS 'Status',
    BB.Name AS 'PN_NAME',
    FROM
    tblPNProperties PNP
    LEFT JOIN tblBusinessBoard BB
    ON PNP.PNID = BB.PNID
    My desired resultset would be to have pnids 28 and 29 to be unique,
    however because I am
    selecting PN_Name it causes the rows to have duplicates. How would I be
    able to obtain my desired resultset? (see below) Is my join correct?
    PNID PN_NUMBER Date1 Date2 Status PN_Name
    ========================================
    ========================
    27 2051 08 Sep 1941 NULL Received NULL
    28 2143 01 Jan 1945 NULL Accepted R Anderson
    29 2151 NULL NULL Accepted W Yarwood
    30 1579 17 Nov 1925 NULL Received NULL
    31 4133 08 Feb 2002 NULL Accepted Mrs L Smith
    Any ideas?
    Thanks
    qh|||Hi Tom,
    thanks for both replies. Unfortunately using JOIN did not work. when
    I type the following
    select * from tblPNProperties
    where pnid = '28'
    I get 1 row
    select * from tblBusinessboard
    where pnid = '28'
    however here I get two rows
    I have a hunch that the data is incorrect.
    Back to the drawing board
    cheers
    qh|||On 2 Dec 2005 03:28:25 -0800, Quackhandle wrote:

    >Hi,
    >Consider the following result set:
    > PNID PN_NUMBER Date1 Date2 Status PN_Na
    me
    > ========================================
    ========================
    >27 2051 08 Sep 1941 NULL Received NULL
    >28 2143 01 Jan 1945 NULL Accepted NULL
    >28 2143 01 Jan 1945 NULL Accepted R Anderson
    >29 2151 NULL NULL Accepted NULL
    >29 2151 NULL NULL Accepted W Yarwood
    >30 1579 17 Nov 1925 NULL Received NULL
    >31 4133 08 Feb 2002 NULL Accepted Mrs L Smith
    >
    >Here is the sql that returns the above:
    >SELECT
    > DISTINCT(PNP.PNID) AS 'PN_ID',
    > PNP.PNNumber AS 'PN_NUMBER',
    > CONVERT(VARCHAR(15), PNP.PNDate, 106) AS 'Date1',
    > CONVERT(VARCHAR(15), PNP.InspectionDate, 106) AS 'Date2',
    > PNP.PNStatus AS 'Status',
    > BB.Name AS 'PN_NAME',
    >FROM
    > tblPNProperties PNP
    > LEFT JOIN tblBusinessBoard BB
    > ON PNP.PNID = BB.PNID
    >My desired resultset would be to have pnids 28 and 29 to be unique,
    >however because I am
    >selecting PN_Name it causes the rows to have duplicates. How would I be
    >able to obtain my desired resultset? (see below) Is my join correct?
    >
    > PNID PN_NUMBER Date1 Date2 Status PN_Na
    me
    > ========================================
    ========================
    >27 2051 08 Sep 1941 NULL Received NULL
    >28 2143 01 Jan 1945 NULL Accepted R Anderson
    >29 2151 NULL NULL Accepted W Yarwood
    >30 1579 17 Nov 1925 NULL Received NULL
    >31 4133 08 Feb 2002 NULL Accepted Mrs L Smith
    >
    >Any ideas?
    >
    >Thanks
    >qh
    Hi qh,
    Since you didn't post CREATE TABLE and INSERT statements, here's a wild
    and completely untested guess:
    SELECT
    PNP.PNID AS 'PN_ID',
    PNP.PNNumber AS 'PN_NUMBER',
    CONVERT(VARCHAR(15), PNP.PNDate, 106) AS 'Date1',
    CONVERT(VARCHAR(15), PNP.InspectionDate, 106) AS 'Date2',
    PNP.PNStatus AS 'Status',
    MAX(BB.Name) AS 'PN_NAME'
    FROM
    tblPNProperties PNP
    LEFT JOIN tblBusinessBoard BB
    ON PNP.PNID = BB.PNID
    GROUP BY
    PNP.PNID,
    PNP.PNNumber,
    PNP.PNDate,
    PNP.InspectionDate,
    PNP.PNStatus
    Best, Hugo
    --
    (Remove _NO_ and _SPAM_ to get my e-mail address)

    One column

    Aside from temp table, in what circumstance one would have only one
    column for a table (be it data or key)? I can't think of any case but
    some of you may.
    Thanks.Doug Baroter (qwert12345@.boxfrog.com) writes:
    > Aside from temp table, in what circumstance one would have only one
    > column for a table (be it data or key)? I can't think of any case but
    > some of you may.

    The system I work with have a couple of one-column one-row tables. These
    tables hold next available number in series which due to business rules
    must be contiguous. They are in tables of their own to avoid a hot spot
    in a table; this was an issue in SQL 6.5.

    We also have a one-column table that holds dates from 1980-01-01 to 2149-12-
    31. If you read a book like Joe Celko's "SQL for Smarties", you will find
    several solutions that are based on a table of numbers. That is, a one-
    column tables with all numbers from 1 up to some limit. Both our date table
    and a table of numbers are auxillary tables that makes other queries
    easier to write.

    --
    Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

    Books Online for SQL Server SP3 at
    http://www.microsoft.com/sql/techin.../2000/books.asp|||On 1 Aug 2003 21:56:54 -0700 in comp.databases.ms-sqlserver,
    qwert12345@.boxfrog.com (Doug Baroter) wrote:

    >Aside from temp table, in what circumstance one would have only one
    >column for a table (be it data or key)? I can't think of any case but
    >some of you may.
    >Thanks.

    I have a few:

    tblCityNoCounty - Cities with no county so the County field on a form
    is conditionally required, e.g. enter "London" as the City and there's
    no need to enter the county. Really should be 2 columns with country
    as well as there's Londons around the world but then at the time it
    was only for the UK.

    tblCountry - Speaks for itself but then I could have other info on
    that like dialling code, etc. At first it did but were dropped thru
    lack of use.

    tblSupplierFav - List of supplier PKs that will show in a supplier
    form.

    tblTitle - Mr, Mrs, Dr, Rev, etc.

    zstblSQLReservedWord - used in a tool I wrote to scan all tables for
    instances of SQL reserved words in table/column names in an Access
    database prior to upsizing.

    --
    Ride Free (but you still have to pay for the petrol)

    (replace sithlord with trevor for email)|||Excellent. It seems in essence the auxillary tables serve to make
    system/solution work better, they themselves are not data tables, I
    use this concept as well.

    I need to catch up on Joe Celko's "SQL for Smarties" after I put out
    immediate fire here.

    Thanks.

    Erland Sommarskog <sommar@.algonet.se> wrote in message news:<Xns93CB67FF99FEBYazorman@.127.0.0.1>...
    > Doug Baroter (qwert12345@.boxfrog.com) writes:
    > > Aside from temp table, in what circumstance one would have only one
    > > column for a table (be it data or key)? I can't think of any case but
    > > some of you may.
    > The system I work with have a couple of one-column one-row tables. These
    > tables hold next available number in series which due to business rules
    > must be contiguous. They are in tables of their own to avoid a hot spot
    > in a table; this was an issue in SQL 6.5.
    > We also have a one-column table that holds dates from 1980-01-01 to 2149-12-
    > 31. If you read a book like Joe Celko's "SQL for Smarties", you will find
    > several solutions that are based on a table of numbers. That is, a one-
    > column tables with all numbers from 1 up to some limit. Both our date table
    > and a table of numbers are auxillary tables that makes other queries
    > easier to write.|||Thank you. What you described, in Erland Sommarskog's term, is auxillary tables.

    Trevor Best <bouncer@.localhost> wrote in message news:<k39niv42a0s86v1htc4kdl8mbvm9v4ecuk@.4ax.com>...
    > On 1 Aug 2003 21:56:54 -0700 in comp.databases.ms-sqlserver,
    > qwert12345@.boxfrog.com (Doug Baroter) wrote:
    > >Aside from temp table, in what circumstance one would have only one
    > >column for a table (be it data or key)? I can't think of any case but
    > >some of you may.
    > >Thanks.
    > I have a few:
    > tblCityNoCounty - Cities with no county so the County field on a form
    > is conditionally required, e.g. enter "London" as the City and there's
    > no need to enter the county. Really should be 2 columns with country
    > as well as there's Londons around the world but then at the time it
    > was only for the UK.
    > tblCountry - Speaks for itself but then I could have other info on
    > that like dialling code, etc. At first it did but were dropped thru
    > lack of use.
    > tblSupplierFav - List of supplier PKs that will show in a supplier
    > form.
    > tblTitle - Mr, Mrs, Dr, Rev, etc.
    > zstblSQLReservedWord - used in a tool I wrote to scan all tables for
    > instances of SQL reserved words in table/column names in an Access
    > database prior to upsizing.

    Friday, March 23, 2012

    ON DELETE CASCADE problem for same table column constraint

    Hello,
    I would like to have table with foreign key referencing to the column of the
    same table. And I want to specify ON DELETE CASCADE to this column, e.g.:
    create table category (
    ID INTEGER IDENTITY(1,1) NOT NULL,
    PARENT_ID INTEGER NULL,
    NAME VARCHAR(100) NOT NULL,
    CONSTRAINT CAT_PK PRIMARY KEY (ID),
    CONSTRAINT CAT_FK FOREIGN KEY (PARENT_ID)
    REFERENCES CAT(ID) ON DELETE CASCADE
    )
    But I receive error:
    --
    Error: java.sql.SQLException: Introducing FOREIGN KEY constraint 'CAT_FK'
    on table 'category' may cause cycles or multiple cascade paths.
    Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints., SQL State: S1000, Error Code: 1785

    It means I cannot specify ON DELETE CASCADE clause.
    HOW CAN I ENSURE CASCADE DELETING FOR ALL RECORDS (ALL CATEGORIES WITH BELONGED SUBCATEGORIES)?
    IS THERE POSSIBILITY TO USE STORED PROCEDURE FOR THIS?
    CAN YOU POST AN EXAMPLE PLEASE?

    Thank you in advance
    best regards,
    Julian LegenyThis is a restriction in all versions of SQL Server that supports cascading constraints. You will have to implement the cascade action using triggers or in your SPs that perform the data modifications.

    Wednesday, March 7, 2012

    OLE DB Destination problem - with keywords

    Destination table has a column name - Partition that is a key word in the DB2 database. But database would execute the query fine if there is "" around the column name - "Partition". When an OLE DB Destination component is used, it throws an error saying column name is a reserved word and that it cannot be used. When put "" around the column name, it fails in the pre-execute phase thinking that "Partition" is the column name instead of Partition. Any ideas to fix this problem would be greatly appreciated?

    What OLE driver are you using for DB2?|||

    Phil,

    I am using 'IBM OLE DB Provider for DB2'. Any suggestions on what I should do to fix the problem?

    |||First, do square brakets work? [Partition]

    Second, is your data flow column called Partition, or something else and you're mapping it to a column named Partition? What I'm getting at here, is you can alias the column in the data flow to be something other than "Partition." That might help.

    Also, you could try using the Microsoft OLE for DB2 driver.

    Saturday, February 25, 2012

    OLE DB DataSource w\ stored procedure not populating column metadata

    I'm having some issues getting OLE DB Data Sources to work w\ stored procs in SSIS. Here's the situation.

    I have an OLE DB Data Source set up to call a stored proc w\ no parameters. The stored procedure loops through a set of databases and inserts data from each database into a results table. I'm attempting to return the results table to SSIS, but the Available External Columns are not populating. However, previewing the query in SSIS does show results. The insert in to the results table is done by a call to sp_executesql.

    I've tried setting the results table up as a temp table, table variable, and static table. I have NOCOUNT set ON and am only returning one recordset. I've seen the other threads in here about similar problems, but none of their solutions seem to work for me.

    Any help would be much appreciated....

    I believe that there are known problems around using SPs in OLE DB Source components. Its something to do with requiring that the query that returns the data is the first statement in the proc. This enables SSIS to understand the metadata of the returned result set.

    I know this doesn't help you in your case though. I do not know if there is a workaround or not having never faced this problem before myself. I hope what I've said above goes some way to helping though.

    -Jamie

    |||I think OLE DB Command will execute the Store proc|||Try converting the sp to a multi-statement table-valued function, giving Data Access Mode for your OLE DB source as SQL Statement and specifying the statement SELECT * FROM your_table_valued_function(); the wizard will gussy the SQL up

    OLe DB Command and Using the value of an input column more than once

    Hi there,

    I have an OLE DB Command which updates a table. However, the command needs to use the value of an input column more than once.

    For example I want to update TableA only if either ColumnA or ColumnB have actually changed: -

    update tableA
    set columnA = ?,
    column B = ?
    where columnC = ?
    AND (columnA != ? OR columnB != ?)

    I can't map the Input column to more than one parameter so I've been forced to create a copy of columnA and ColumnB as input columns so I can map to the extra paramters that the Command shape expects.

    I also attempted to modify the command syntax so it set up variables for the 3 values required and then set the values to parameters - but I get a very unhelpful syntax error message: -

    declare @.ValueA varchar(50),
    @.ValueB varchar(50),
    @.ValueC varchar(50)
    select @.ValueA = ?,
    @.ValueB = ?,
    @.ValueC = ?,
    update tableA
    set columnA = @.ValueA ,
    column B = @.ValueB
    where columnC = @.ValueC
    AND (columnA != @.ValueA OR columnB != @.ValueB)

    Any suggestions?

    anydobbo wrote:

    Hi there,

    I have an OLE DB Command which updates a table. However, the command needs to use the value of an input column more than once.

    For example I want to update TableA only if either ColumnA or ColumnB have actually changed: -

    update tableA
    set columnA = ?,
    column B = ?
    where columnC = ?
    AND (columnA != ? OR columnB != ?)

    I can't map the Input column to more than one parameter so I've been forced to create a copy of columnA and ColumnB as input columns so I can map to the extra paramters that the Command shape expects.

    Yeah, that's what you have to do!

    anydobbo wrote:

    I also attempted to modify the command syntax so it set up variables for the 3 values required and then set the values to parameters - but I get a very unhelpful syntax error message: -

    declare @.ValueA varchar(50),
    @.ValueB varchar(50),
    @.ValueC varchar(50)
    select @.ValueA = ?,
    @.ValueB = ?,
    @.ValueC = ?,
    update tableA
    set columnA = @.ValueA ,
    column B = @.ValueB
    where columnC = @.ValueC
    AND (columnA != @.ValueA OR columnB != @.ValueB)

    Any suggestions?

    I may be wrong but I don't think you can do that. The OLE DB Command accepts a DML statement but not a statement block (as far as I know).

    -Jamie

    |||Thanks Jamie

    OlE Db Command

    Hi,

    Iam trying to generate the increment value for a column by taking Maximum value of that field by using OLE DB Command Transformation.

    This is the query iam using for that :
    select max(ApplicationId)+1 as APPLICATIONID from Source..Applications

    Iam finding difficulty in getting the 'APPLICATIONID' as the out put from OLEDB Transformation.OLE DB is not going to work with out any parameters ?can you please throw some light on this .First time iam using this transformation.

    Another alternate solution is generating through script task (Thanks Jamie Thomson for his article).But i dont know how i can modify this to get the Max value instead of declaring some constant value for increment

    Public Class ScriptMain
    Inherits UserComponent
    Dim Counter As Int32
    Public Sub New()
    Counter = 1006
    End Sub

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    '
    ' Add your code here
    '
    Counter += 1
    Row.APPLICATIONTASKID = Counter

    End Sub

    End Class
    Please me help me in finding one solution from the above two

    Thanks
    Niru
    No replies ..

    Am I dint explained properly or nobody are aware of this?

    Thanks
    Niru
    |||

    If I understand your question correctly, you're asking to generate a surrogate key id (1,2,3,..) which key id is started from last key id + 1 from your source table. If yes, you can try this:

    On control flow, create an Execute SQL task with your select statement:

    select isnull(max(ApplicationId),1) as APPLICATIONID from Source..Applications

    Set Result Set property = Single Row

    Create a variable, on the Result Set assign your variable.

    On data flow, create a column, ex. ApplicationKeyID set to null. Follow by script component task; in Input Columns, select the ApplicationKeyID and Usage type = ReadWrite. On Script, type in the variable name for ReadOnlyVariables property. And your script will look something like this:

    Public Class ScriptMain

    Inherits UserComponent

    Dim Counter As Integer = 0

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

    Row.ApplicationKeyID = Variables.VariableName+ Counter

    Counter = Counter + 1

    End Sub

    End Class

    Hope this does not cause any more confusion for you...

    Monday, February 20, 2012

    Old, deleted Identity values re-used?

    If I have an Identity-declared column, the table has lots of rows and I start deleteting records - will any old, deleted identities be re-used (without an explicit re-seed) ?
    (I'm talking about numerical Identities, not these GUID things)No. Not without manipulating the IDENTITY column. The exception being that if you TRUNCATE the table, then the seed will reset to the floor value.

    Regards,

    hmscott|||yeah,it can be used
    need to set identity off
    insert statement
    reset identity on