Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Convert "current_timestamp"

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-03 : 13:52:56
Have following code:


declare @DateTime varchar(50)
set @DateTime = convert(varchar(50), current_timestamp, 121)

exec('insert into ZyTax.dbo.ttable(
report_state, report_datetime
select ztadds, ' + @DateTime +
' from AS400SRV_MSDASQL.VGSYS400.' + @AliasLibrary + '.' + @SourceFile)


Now it gives me error on @DateTime in the "select". If I use code 108 it gives error as well. It works fine for code 112. I need to capture both date and time.

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-03-03 : 13:59:22
hi,

can you do print and show us what the concatenated stuff looks like. I think you are missing a parenthesis after report_datetime?
DECLARE @query VARCHAR(MAX)
SET @query ='insert into ZyTax.dbo.ttable(report_state, report_datetime)
select ztadds, ' + @DateTime +
' from AS400SRV_MSDASQL.VGSYS400.' + @AliasLibrary + '.' + @SourceFile + ')'
PRINT @query
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-03 : 14:10:00
Here is the complete code. It works and inserts the date when I use code 112, but not when I use 121 or 108. I think it has to do with "-" or ":".

declare @DateTime varchar(50)
set @DateTime = convert(varchar(50), current_timestamp, 108)

begin transaction
exec('insert into ZyTax.dbo.ttable(
report_state, report_year, report_month, company, destination_county,
carrier_name, carrier_fein, mode_code, origin_name, origin_city,
origin_state, origin_code, destination_name, destination_city, destination_state,
destination_code, consignor_name, consignor_fein, buyer_name, buyer_fein,
seller_name, seller_fein, manifest_date, manifest, net, gross, billed,
product, business_event, terms, effective_date, invoice_number, invoice_date,
dest_splc, carrier_scac, origin_splc, taxtype, transtype, recordtype,
fuelusetype, position_holder, position_fein, ok_to_import, seller_qualifier,
origin_option, cons_qualifier, carrier_qualifier, buyer_qualifier, dest_option,
div_dest_name, div_dest_option, div_dest_id_code, div_dest_state, div_dest_city,
div_dest_county, div_dest_zip, destination_dep, destination_license, load_flag,
scrubbed_flag, origin_county, div_number, imp_ver_number, seller_control_name,
cons_control_name, carrier_control_name, buyer_control_name, destination_zip,
origin_zip, seller_637, purchase_date, receipt_date, freight_paid_by,
vehicle_make, vehicle_no, vehicle_model, vehicle_license, vehicle_beg_odo,
vehicle_end_odo, vehicle_miles, credit_memo_no, credit_memo_date, cc_no,
flight_no, flight_date, flight_stop, memo_fueluse, prod_subtype,
dest_license_type, buyer_st_id, seller_st_id, carrier_st_id, cons_st_id, buyer_st_id_type,
seller_st_id_type, carrier_st_id_type, cons_st_id_type, ca_oper_dsl_no,
loc_code, exempt_code, useruid, sold_to_customer_no, ship_to_customer_no,
payer_customer_no, source_document_no, taxable_gallons, position_qualifier,
position_control_name, position_637, orig_jurisdiction_2, dest_jurisdiction_2,
gal_price, prod_converted, prod_blended_1, prod_blended_2, date_shipped,
tax_collected, airport_fuel_sold_to, name_auth_purchaser, title_auth_purchaser,
unpaid_special_tax, div_dest_splc, buyer_state, buyer_city, seller_state,
seller_city, origin_custom_id_code, dest_custom_id_code, div_dest_custom_id_code,
sched_type, exemption_type, tax1_exempt, tax2_exempt, tax3_exempt, tax4_exempt,
tax5_exempt, tax6_exempt, tax7_exempt, tax8_exempt, tax9_exempt, tax10_exempt,
tax11_exempt, blend_1_gross, blend_1_net, blend_1_billed, blend_2_gross,
blend_2_net, blend_2_billed, blend_3_gross, blend_3_net, blend_3_billed,
base_prod_gross, base_prod_net, base_prod_billed, prod_blended_3,
self_carried_flag, borderzone_flag, schedule_code, exchange_flag, customer_key,
sched_category, alt_mode_code, company_owned, taxes_applied, original_product,
exemption_type_2, sched_category_2, company_taxpayertype, origin_dep_number,
origin_address1, origin_address2, dest_address1, dest_address2,
position_st_id, position_st_id_type, buyer_street, seller_street, origin_street,
destination_street, div_dest_street, buyer_address1, buyer_address2, seller_address1,
seller_address2, div_dest_address1, div_dest_address2, vehicle_license_state,
exchange_position_holder, exchange_position_fein, exchange_position_qualifier,
exchange_position_control_name, exchange_position_holder_637,
exchange_position_st_id, exchange_position_st_id_type, error_status,
dest_country, origin_country, origin_license, origin_license_type, custom1 --,
--custom2, custom3, custom4, custom5
)

Select ztadds, ztyear, zt#mt, ztco, ztdl01, ztdsc, ztein, ztmot, ztdl02, ztcity,
ztrp14, ztzip, ztdl03, ztdl04, ztssst, ztvvz, ztdsc1, ztcein, ztdsc2, ztbein,
ztdsc3, ztsein, zt#dsc, zt#ds2, ztnetg, ztqty, zttot$, ztprd1, ztbev, ztterm,
convert(datetime,ztdef,110),
ztinv#, convert(datetime,ztdtsp,110),
ztds, ztcrrt, ztorsp, zttxty, zttrty, ztrcty, ztftyp,
ztpohd, ztpein, ztokim, ztsllq, ztogop, ztcqua, ztcrrq, ztbuyq, ztdeso, ztdidn,
ztdivo, ztdivi, ztdivs, ztdivc, ztdict, ztdivz, ztdsdp, ztdsli, ztlflg, ztsflg,
ztorct, ztdivn, ztivrn, ztslcn, ztccna, ztcrrc, ztbcn, ztdesz, ztogzp, zts637,
convert(datetime,ztpodt, 110),
convert(datetime,ztrcdt, 110),
ztfpby, ztdl05, ztvnum, ztmod, ztvlic, ztvbod, ztveod, ztvmil,
ztcme#, convert(datetime,ztcmdt, 110),
ztccno, ztflg#, convert(datetime,ztflgd, 110),
ztflgs, ztmemf, ztpdty, ztdelt, ztbsti,
ztssti, ztcsti, ztcnsi, ztbstt, ztsstt, ztcstt, ztcnst, ztcodn, ztlocc, ztexcd,
ztuuid, ztcust, ztscus, ztpcus, ztsdoc, zttxgl, ztpoq, ztpocn, ztp637, ztogju,
ztdsju, ztglpr, ztpdcv, ztpdb1, ztpdb2, ztdats, zttxcl, ztafst, ztaupu, zttupu,
ztustx, ztddsp, ztbst, ztbcty, ztssta, ztscty, ztogcc, ztdscc, ztdvcc, ztscht,
ztexty, ztext1, ztext2, ztext3, ztext4, ztext5, ztext6, ztext7, ztext8, ztext9,
ztex10, ztex11, ztbl1g, ztbl1n, ztbl1b, ztbl2g, ztbl2n, ztbl2b, ztbl3g, ztbl3n,
ztbl3b, ztbspg, ztbspn, ztbspb, ztpdb3, ztscfg, ztbzfg, ztschc, ztexfg, ztcuky,
ztscct, ztaltm, ztcoow, zttxap, ztogpd, ztety2, ztsca2, ztcotx, ztogdn, ztoga1,
ztoga2, ztdes1, ztdes2, ztpsid, ztpsty, ztbust, ztslst, ztogst, ztdsst, ztdvst,
ztbad1, ztbad2, ztsad1, ztsad2, ztdad1, ztdad2, ztvlst, ztephl, ztepei, ztepql,
ztepcn, zte637, ztepid, ztepty, ztests, ztdcty, ztogty, ztogli, ztoglt, ' + @DateTime +
' from AS400SRV_MSDASQL.VGSYS400.' + @AliasLibrary + '.' + @SourceFile)
COMMIT TRANSACTION
if @@error <> 0
begin
set @RetValue = 'Error: upload to ZyTax failed'
set @InsertOK = 0 -- false
end


Error: Incorrect syntax near ':'
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-03-03 : 14:48:46
can you do dump the query into a @query variable and just show us the resulting query string? that helps to debug your problem. but i think you are right : is the problem but it can work it depends how you are concatenating things..
HUGE INSERT man!
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-03 : 15:07:03
hmmm, a little bit embarassing, but how do I dump the query string into a variable in my case (not very familiar with sql and all the features), sorry... thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-03 : 15:09:22
declare @sql nvarchar(4000)

set @sql = what you are passing to EXEC

print @sql -- this is what we need to see

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-04 : 07:57:52
Did this:

declare @mysql VARCHAR(400)
SET @mysql = 'insert into ZyTax.dbo.ttable(
report_state, report_datetime
select ztadds, ' + @DateTime +
' from AS400SRV_MSDASQL.VGSYS400.' + @AliasLibrary + '.' + @SourceFile



Using code 121 the value of select string is:

insert into ZyTax.dbo.ttable(                           report_state, report_datetime
select ztadds, 2009-03-04 07:50:06.947 from AS400SRV_MSDASQL.VGSYS400.VGITFRLIB.F55125
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-04 : 08:08:26
Dates need to be enclosed too!

'' + @DateTime + '''


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2009-03-04 : 08:43:10
That worked. Thank you.


Go to Top of Page
   

- Advertisement -