June 24, 2008 at 10:53 am
Hi all,
I've got to populate a table in a DB in a particular language. This language can be deciphered from finding the most popular language used by a set of users.
The problem is I can't get the INPUT statement to work!!! Grrr!!!
See below:
SELECT CASE WHEN 1 = 1
THEN
BULK INSERT DBA.InterfacingLabels_TB FROM 'c:\InterfacingLabels_DE.dat'
ELSE
BULK INSERT DBA.InterfacingLabels_TB FROM 'c:\InterfacingLabels.dat'
END
The conditional 1 = 1 is just to illustrate the point.
The weird thing is that if I replace the INPUT INTO lines with numeric values, there is a valid output.
So does anyone know if it is impossible to conditionally insert data from a file according to the result of a query? I don't see why this should be.
Many thanks,
James
June 24, 2008 at 11:09 am
themancorp (6/24/2008)
Hi all,I've got to populate a table in a DB in a particular language. This language can be deciphered from finding the most popular language used by a set of users.
The problem is I can't get the INPUT statement to work!!! Grrr!!!
See below:
SELECT CASE WHEN 1 = 1
THEN
BULK INSERT DBA.InterfacingLabels_TB FROM 'c:\InterfacingLabels_DE.dat'
ELSE
BULK INSERT DBA.InterfacingLabels_TB FROM 'c:\InterfacingLabels.dat'
END
The conditional 1 = 1 is just to illustrate the point.
The weird thing is that if I replace the INPUT INTO lines with numeric values, there is a valid output.
So does anyone know if it is impossible to conditionally insert data from a file according to the result of a query? I don't see why this should be.
Many thanks,
James
INPUT is not a valid keyword in t-sql. what system are you working with? maybe you mean INSERT?
also, the way you do conditional logic is with IF statements. CASE is not a logical keyword - it gives you an expression. Also there is no IF/THEN in t-sql.
so what you want is something more like:
IF (@mylanguage = 'german')
BEGIN
BULK INSERT DBA.InterfacingLabels_TB FROM 'c:\InterfacingLabels_DE.dat'
END
ELSE
BEGIN
BULK INSERT DBA.InterfacingLabels_TB FROM 'c:\InterfacingLabels.dat'
END
---------------------------------------
elsasoft.org
June 24, 2008 at 12:03 pm
You need an IF, not "SELECT.. CASE.. THEN.."
IF 1 = (SELECT 1)
BEGIN
...
END
ELSE
BEGIN
...
END
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
June 25, 2008 at 3:42 am
Sorry, I didn't make myself very clear in my initial post. This is for Sybase and NOT SQL Server. I WILL need a SQL Server version of this procedure as well.
I've now made a procedure of this task.
CREATE PROCEDURE dba.spd_PopulateInterfacingLabels
@strLanguageCode VARCHAR(2)
AS
IF @strLanguageCode = 'DE'
BEGIN
INPUT INTO DBA.InterfacingLabels_TB FROM c:\InterfacingLabels_DE.dat DELIMITED BY ''
--EXECUTE('')
END
ELSE
BEGIN
INPUT INTO DBA.InterfacingLabels_TB FROM c:\InterfacingLabels.dat DELIMITED BY ''
--EXECUTE('')
END
GO
This procedure also doesn't work. I've got the INPUT (BULK INSERT in SQL Server) commented out in the example above, and this works, but as soon as I put uncomment the lines it fails.
June 25, 2008 at 7:09 am
Well, I am not that familiar with SyBase, but are you getting any error messages?
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy