15 Execute SQL Task in SSIS | Use variables in Execute SQL task in SSIS

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 เม.ย. 2017
  • Execute SQL Task in SSIS | Use variables in Execute SQL task in SSIS
    Download the file\script used in the Video from below link
    drive.google.com/drive/folder...
    SSIS Tutorials: • SSIS Tutorials
    SSIS real time scenarios examples: • SSIS real time scenari...
    SSIS Interview questions and answers: • SSIS Interview questio...
    Execute SQL Task in SSIS
    How execute SQL Task works in SSIS?
    Why we use execute SQL task in SSIS?
    How do I run an SQL file in SSIS?
    What is the difference between execute SQL task and execute SQL task?
    Happy Learning.
    If you have any questions or suggestions please comment on the video or write to me at “aqil33@gmail.com”
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 103

  • @nivetha.meceskct6693
    @nivetha.meceskct6693 3 ปีที่แล้ว

    Aqil you are the best SSIS person the video is very much helpful you have covered variable and parameters as well with execute SQL task....thanks a lot for your help

    • @learnssis
      @learnssis  3 ปีที่แล้ว

      So nice of you.

  • @christopherhorton9198
    @christopherhorton9198 5 หลายเดือนก่อน

    Thanks. That was very informative. Keep it up !

    • @learnssis
      @learnssis  5 หลายเดือนก่อน

      Thank you Christopher.

  • @manishbaburaisingh1985
    @manishbaburaisingh1985 4 ปีที่แล้ว

    AWSM

  • @vijaybodkhe8379
    @vijaybodkhe8379 2 ปีที่แล้ว

    Thank you for sharing Knowledge

    • @learnssis
      @learnssis  2 ปีที่แล้ว +1

      Thank you Vijay.

  • @LucasMaster
    @LucasMaster 10 หลายเดือนก่อน +3

    if you have problems on the second sql statement (using variables), remove the 'go' from the query

    • @AnkitMehta-qe8on
      @AnkitMehta-qe8on 2 หลายเดือนก่อน

      Great find man, great help😊

    • @KRaJWanders
      @KRaJWanders หลายเดือนก่อน

      Thanks, that helped

  • @mdsamiulislam2522
    @mdsamiulislam2522 3 ปีที่แล้ว

    Aqil, My dear brother, i am samiul from bangladesh... really helpful your guide line

    • @learnssis
      @learnssis  3 ปีที่แล้ว

      Thank you Samiul for watching the videos.

  • @dhirendramaurya5361
    @dhirendramaurya5361 ปีที่แล้ว

    Awesome all videos

    • @learnssis
      @learnssis  ปีที่แล้ว

      Thank you Dhirendra.

  • @iveebhuyan
    @iveebhuyan 2 ปีที่แล้ว

    nicely explained

    • @learnssis
      @learnssis  2 ปีที่แล้ว

      Thank you so much Bhuyan for appreciating the video.

  • @rightplacetoeat7420
    @rightplacetoeat7420 5 ปีที่แล้ว

    Hi sir , Thanks for your video.You made a such a nice video. If you dont mind please make a video on real time example bY using the Execute sql task ..Thanks in advance

    • @learnssis
      @learnssis  5 ปีที่แล้ว

      Its good to know that you liked the video. Sure I will try to make a video as per your suggestion. Thank you.

    • @learnssis
      @learnssis  5 ปีที่แล้ว +1

      Its good to know that you liked the video. Sure I will try to make a video as per your suggestion. Thank you.

  • @user-vy5ck5sv2l
    @user-vy5ck5sv2l ปีที่แล้ว

    Hi Aqil, if i want to insert only the name. what format should be used. I created a table with one column (name alone), when i give the below insert under expression, the evaluate expression throws error.
    insert into Person values (@[User::Name] )

    • @learnssis
      @learnssis  ปีที่แล้ว

      You would need to write
      "insert into Person values
      '"+ @[User::Name] +"'
      "

  • @SoftwareCouple
    @SoftwareCouple 2 ปีที่แล้ว

    Sir after giving the server name in the top for the connection in the below drop down i am not able to find the database name.please help me

    • @learnssis
      @learnssis  2 ปีที่แล้ว

      For Database Name it will be Initial_Catalog

  • @Jigyasuh
    @Jigyasuh 2 ปีที่แล้ว

    Hi Aqil,
    I got this error while executing using variable:
    "[Execute SQL Task] Error: Executing the query "INSERT INTO PERSONS VALUES(?,?,?)" failed with the following error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly."
    Please suggest what to do?

    • @caravindpandi
      @caravindpandi 2 ปีที่แล้ว

      have u found the solution for this error?
      I too got this error

    • @Jigyasuh
      @Jigyasuh 2 ปีที่แล้ว

      @@caravindpandiNo

    • @MpT_Head
      @MpT_Head ปีที่แล้ว

      I had the same. I removed the 'go' from the query and it worked fine. I had reused the first query and just changed the values but when I checked, there's no 'go' in the second 'variable' query. Did you do the same as I did?

  • @MVinodKumar-tt1tu
    @MVinodKumar-tt1tu 8 หลายเดือนก่อน

    Hello Sir,
    First Doubt: So through variables in this case each time we can enter only each record from variables into table? or can we enter multiple records at single time using variables?....
    Second Doubt:
    INSERT INTO PERSONS VALUES ('"+ @[User::Name] +"','"+ @[User::Gender] +"','"+ (DT_WSTR,12)@[User::Age] +"')
    In this while using variables to enter the values into table, why we used single quote and double quote both. First single quotes and inside it double quotes and inside variable.... Please explain sir

    • @learnssis
      @learnssis  8 หลายเดือนก่อน +1

      1. At a time we can insert only one record from variable, because at one time you can store only one value in a variable.
      2. If we need to use the string variable inside expression, then the syntax is that we should first write a double quote ", then + sign then drag and drop the variable then put the + sign then put the double quote ". This way we will get the value from variable. however if you have noticed if you need to insert a string value into a sql server table then we enclose the string in a single quote, same is the case here that we got the value but now to enclose the value within single quote we need to put a single quote ' before the double quote " and then in the end put a single quote ' after double quote ".

  • @VishalJaybhaye-kq4hh
    @VishalJaybhaye-kq4hh 5 วันที่ผ่านมา

    SIr it is giving me this error when we created parameters for Ram person, Execute SQL Task: Executing the query "insert into Person values (?,?,?)" failed with the following error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    Task failed: Execute SQL Task. Can u pls tell me the issue?

    • @learnssis
      @learnssis  5 วันที่ผ่านมา

      Are you using Go statement inside the query ? Do not use any go statements.

  • @sathiyamoorthi9224
    @sathiyamoorthi9224 6 หลายเดือนก่อน

    Hi Aqil ,your video all are very useful.can you please share any video it,s getting data from one table based on smallest id and max id between data only daily .the daily trucate load. Thanks in Advance

    • @learnssis
      @learnssis  6 หลายเดือนก่อน

      Not sure if I got your question currently.
      1. First you can use execute sql task to truncate the data from destination table. Put a truncate query in that.
      2. Use a data flow task to pull the data from source table. And Use the OLE DB source, inside OLE DB source select sql command option and write your query similar to below one, it will select data ranging from min to max
      declare @min_id int, @max_id int
      set @min_id = (select min(id) from [Customer])
      set @max_id = (select max(id) from [Customer])
      select * from Customer where id between @min_id and @max_id
      3. Now use the OLE Db destination to write the data to a sql server table that you truncated in step 1.

    • @sathiyamoorthi9224
      @sathiyamoorthi9224 6 หลายเดือนก่อน

      Thanks Aqil

    • @sathiyamoorthi9224
      @sathiyamoorthi9224 6 หลายเดือนก่อน

      @@learnssis I need to check duplicate data between the min id and Max I'd in the table .if any possible to store min id and Max Id store in variable.could you pls let me know Thanks for understanding!

    • @learnssis
      @learnssis  6 หลายเดือนก่อน

      @@sathiyamoorthi9224You can write a query similar to below in execute sql task and select the option single result set
      declare @min_id int, @max_id int
      set @min_id = (select min(id) from [Customer])
      set @max_id = (select max(id) from [Customer])
      select @min_id, @min_id
      Now in the result set, add first result set name 0 and select the ssis variable that will hold the min id and the add another result set and name it as 1 and select another ssis variable that will hold the max id.
      To select only the distinct records you can see how you can select only distinct records.
      You can use row_number function along with cte to select the unique records.
      th-cam.com/video/8ohs43g9X5Y/w-d-xo.html
      th-cam.com/video/WRCu-7avec8/w-d-xo.html

    • @sathiyamoorthi9224
      @sathiyamoorthi9224 6 หลายเดือนก่อน

      @@learnssis Thanks you!

  • @sathiyamoorthi9224
    @sathiyamoorthi9224 6 หลายเดือนก่อน

    Hi Aqil,
    Thanks for videos, i have one doupt.
    To find duplicate data
    Select name,gender,memberid,,,,count(1 ) from ABC
    Group by name,gender,memberid
    Having count(1)>1
    I need to insert above query duplicate result set in temporary table and mail send to user also copy of duplicate result set . After that If find any duplicate data i need to update . Could you pls let me know how will achieve in ssis package
    Thanks in Advance!!

  • @oshriamir
    @oshriamir 9 หลายเดือนก่อน

    Hi all , i got this error : [Execute SQL Task] Error: Executing the query "insert into NPerson values (?,?,?)" failed with the following error: "Parameter name is unrecognized.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    What i can do ?

    • @learnssis
      @learnssis  9 หลายเดือนก่อน

      Are you providing 3 parameters to this query ?
      insert into NPerson values (?,?,?)

  • @learner_SSIS
    @learner_SSIS ปีที่แล้ว

    Lovely Sir 😀

  • @phaninath8237
    @phaninath8237 7 ปีที่แล้ว

    nice video bro can u give me the query to connect multiple Db.

    • @learnssis
      @learnssis  7 ปีที่แล้ว

      Hi Phani, thanks for your question. In SSIS if you want to connect to a SQL Server database then you can drag and drop a Data flow task from SSIS toolbox into Control Flow window. After that double click the data flow task and if you are looking to read data from sql server database, then drag and drop an OLEDB Source from Data Flow Sources to the Data Flow Task Or if you want to write data to SQL Server then you can drag and drop the OLE DB Destination into the Data FLow Task. Once done you can connect to a SQL server database. If you need to connect to multiple databases at a time then you can drag and drop multiple OLEDB sources into the Data FLow Task.
      You can see my video "Copy data from one sql server instance to another" to see how to connect to a sql server database. Similarly you can either drag and drop multiple Data Flow Task and do the same thing what I have done for one Data Flow Task
      th-cam.com/video/z78-R-SAZK4/w-d-xo.html

    • @learnssis
      @learnssis  7 ปีที่แล้ว

      Okay, I have connected to multiple databases at a time in below video, just take a look at this video if it can be of your use
      th-cam.com/video/z78-R-SAZK4/w-d-xo.html

    • @phaninath8237
      @phaninath8237 7 ปีที่แล้ว

      thanks bro

  • @sanjeevaranisalluri9976
    @sanjeevaranisalluri9976 ปีที่แล้ว

    [Execute SQL Task] Error: Executing the query "create table persons
    (id int,name varchar(20),gend..." failed with the following error: "There is already an object named 'persons' in the database.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

    • @learnssis
      @learnssis  ปีที่แล้ว +1

      In the execute sql task, before creating the Persons table add this clause
      IF NOT (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'Persons'))
      Now Persons table will only be created if it does not exists in the database.

  • @abhi-vt2xg
    @abhi-vt2xg 2 ปีที่แล้ว

    Please do comment that expression which you used for dynamic entry

    • @learnssis
      @learnssis  2 ปีที่แล้ว +1

      Hi, Can you try this one
      INSERT INTO PERSON VALUES('"+@[User::Name]+"', '"+@[User::Gender]+"', "+ (DT_WSTR,12) @[User::Gender]+")
      The Rule is simple.
      1. When you start writing any code start the code with double quote " and close it with double quote " as well.
      2. Any string value will be surrounded by single quote followed by double quote, then put a + sign and then put SSIS variable there and after it, again put a + single, followed by double quote single quote like below
      ' " + @[User::FILEPATH] + " '
      3. Any Int SSIS variable will be surrounded by just double quote. So put a double quote " then put a + sign, then place the SSIS variable there and put the + sign there and then put the double quote there. You also need to convert the Int to string so that it can be used in the expression. An example is below
      " + (DT_WSTR,12) @[User::COUNT] + "

  • @sachinnavik4904
    @sachinnavik4904 2 ปีที่แล้ว

    Hello sir i am not able to see integreation servuce catalog node in ssms my sql server is 2019

    • @learnssis
      @learnssis  2 ปีที่แล้ว

      Right click on Integration services catalog and click on Create Catalog (7:43)
      th-cam.com/video/xaBIYxe5qVA/w-d-xo.html

  • @data9051
    @data9051 2 ปีที่แล้ว +2

    ERROR:
    [Execute SQL Task] Error: Executing the query "insert into persons values (?.?.?)" failed with the following error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    SOLUTION:
    I had the same issue and fixed this issue. In the video he actually copy pastes a different Query and you can see it for a short second to be able to copy it. Deleting GO and CREATE TABLE parts of the query wasn't enough because I needed to actually change the GO statement to 'ON [PRIMARY]'
    Query below:
    IF NOT EXISTS (
    SELECT *
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_NAME = N'Person')
    CREATE TABLE PERSON(
    ID INT IDENTITY,
    NAME VARCHAR(50),
    GENDER VARCHAR(1),
    AGE INT)
    ON [PRIMARY]
    INSERT INTO PERSON VALUES (?,?,?)

    • @learnssis
      @learnssis  2 ปีที่แล้ว

      Its good to know that you were able to fix it.

    • @AOAMuse
      @AOAMuse 5 หลายเดือนก่อน

      Or just remove GO

    • @Mohamed-yb2xy
      @Mohamed-yb2xy 4 หลายเดือนก่อน

      hi i get the same error o tried different solution but i did not solve the probleme can you help me this is the query i use : INSERT INTO SSISParameterValues (ParameterName, ParameterValue, CreatedDate)
      VALUES ('PackageName',CAST(? AS varchar(500)), GETDATE()); i tried to not use parameters in the query and it runs correctly but when i use parameter or variable i get this same error ?

  • @krishnachaitanyareddy2781
    @krishnachaitanyareddy2781 2 ปีที่แล้ว

    wow you can insert the sql statements with 5 different ways.

    • @learnssis
      @learnssis  2 ปีที่แล้ว

      Glad you found it useful.

  • @sureshareti2843
    @sureshareti2843 หลายเดือนก่อน

    Bhaiyya can we use variable object type in expression in ssis?
    If yes please tell how to do that

    • @learnssis
      @learnssis  หลายเดือนก่อน

      Sorry, don't know if we can use it, never tried that.

    • @sureshareti2843
      @sureshareti2843 หลายเดือนก่อน

      @@learnssis no worries bhaiyya
      I tried it but it's not working

  • @yuvanak1028
    @yuvanak1028 2 ปีที่แล้ว +1

    Nice Lecture. But when I have tried using parameters. I was getting the following error. "Multi-step OLE DB operation generated errors. Check each OLE DB Status value, if available. No work was done ". Possible reason for failure with query,"Resultset" property is not set correctly. Can you please help.

    • @learnssis
      @learnssis  2 ปีที่แล้ว

      Are you returning any value from execute sql task and assigning it to an SSIS variable ?

    • @abhi-vt2xg
      @abhi-vt2xg 2 ปีที่แล้ว

      @@learnssis [Execute SQL Task] Error: Executing the query "insert into persons values (?.?.?)" failed with the following error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
      -------
      THIS ERROR IM GETTING

    • @Jigyasuh
      @Jigyasuh 2 ปีที่แล้ว

      @@learnssis Same error, what to do?

    • @Jigyasuh
      @Jigyasuh 2 ปีที่แล้ว

      Same error what to do?

    • @abhi-vt2xg
      @abhi-vt2xg 2 ปีที่แล้ว

      Hi sir help out with this error

  • @LearnYouAndMe
    @LearnYouAndMe 4 หลายเดือนก่อน

    please provide sql expression script in your description. I am not to write it in right way.

    • @learnssis
      @learnssis  4 หลายเดือนก่อน

      You can download the script from the link in the description of the video
      if not exists(select * from information_schema.tables where table_name = 'Person')
      create table Person(Id int identity, Name varchar(50), Gender varchar(1), AGE int)
      go
      insert into Person values ('ABHISHEK','M', 35)
      ---------------------
      if not exists(select * from information_schema.tables where table_name = 'Person')
      create table Person(Id int identity, Name varchar(50), Gender varchar(1), AGE int)
      insert into Person values (?,?,?)
      ----------------------
      "if not exists(select * from information_schema.tables where table_name = 'Person')
      create table Person(Id int identity, Name varchar(50), Gender varchar(1), AGE int)
      insert into Person values ('"+ @[User::Name] +"','"+ @[User::Gender] +"','"+(DT_WSTR,12) @[User::Age] +"')
      "

  • @kishanbhise4733
    @kishanbhise4733 2 ปีที่แล้ว

    Sir it will be better if you make the video little more lengthy but explanation needs to be little slower I mean the navigation was too fast to catch

    • @learnssis
      @learnssis  2 ปีที่แล้ว

      Okay, got it. Will take care for future videos.

  • @sanjeevaranisalluri9976
    @sanjeevaranisalluri9976 ปีที่แล้ว

    I have executing error plz tell me how can I resolve this

    • @learnssis
      @learnssis  ปีที่แล้ว

      In the execute sql task, before creating the Persons table add this clause
      IF NOT (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'Persons'))
      Now Persons table will only be created if it does not exists in the database.

  • @asadnaseer7291
    @asadnaseer7291 3 ปีที่แล้ว

    HI,
    I want to read from sql server database and convert the output into csv and place that into FTP server every 10 minutes, how can we do this?
    Can you please guide or make a video on this?

    • @learnssis
      @learnssis  3 ปีที่แล้ว

      Hi, you need to use a data flow task and load the data from sql server to csv and then add a FTP task to move the file to FTP server.
      Below video can do the export thing.
      th-cam.com/video/n94-pFXP8eA/w-d-xo.html
      I don't have access to FTP server, thus I did not made a video on moving data to FTP server, probably you can find a video on moving file to FTP server.
      Then you can schedule the SSIS package to run on a particular schedule. I have a video to schedule the ssis package using SQL Agent job. Thanks.

    • @asadnaseer7291
      @asadnaseer7291 3 ปีที่แล้ว

      @@learnssis Thank you very much for your response. Can you please mention the link for scheduling also? Then I have to create another package for FTP task, as I am unable to direct Flat File output to the FTP task

    • @learnssis
      @learnssis  3 ปีที่แล้ว

      @@asadnaseer7291
      Below link can help you to schedule an SSIS package
      th-cam.com/video/qrV2FbQpU3I/w-d-xo.html

  • @rammohan1935
    @rammohan1935 ปีที่แล้ว

    Hi, i have one doubt for last approach how do we pass variables. can you explain me

    • @learnssis
      @learnssis  ปีที่แล้ว

      In this video I have shown how to pass variables to sql query.
      You can write the sql query in expressions, under sql query and then you can use system or user defined variable there.

    • @rammohan1935
      @rammohan1935 ปีที่แล้ว

      @@learnssis my query is in .SQL file

    • @learnssis
      @learnssis  ปีที่แล้ว

      @@rammohan1935 In that case, you would need to read the file in the script task using C# code and then if you know what vales you want to provide then you can replace the values with ssis variables using C# code there is a replace function in C# which can be used and then you can assign the final result \ final query to an ssis variable which can be executed using an execute sql task or you can execute it inside script task as well, its kind of pure C# work, there are no inbuilt tasks in ssis to perform this task.

    • @rammohan1935
      @rammohan1935 ปีที่แล้ว

      @@learnssis thank you very much for information

    • @rammohan1935
      @rammohan1935 ปีที่แล้ว

      I approached this way but getting error like Error Failed to lock variable

  • @Maths-learn123
    @Maths-learn123 2 ปีที่แล้ว

    Hi SQL code was not clear and can u the snd the code in Google drive also the file is not there

    • @learnssis
      @learnssis  2 ปีที่แล้ว

      Sorry for that. I will try to find the code.

    • @Maths-learn123
      @Maths-learn123 2 ปีที่แล้ว

      I had error that "there is already an object named person in the database" when iam trying excute the variables it was throwing the above error

    • @Maths-learn123
      @Maths-learn123 2 ปีที่แล้ว

      @@learnssis the video was not properly zoomed the code is not clear kindly pls make this video clarity or provide the code

    • @learnssis
      @learnssis  2 ปีที่แล้ว

      @@Maths-learn123 you can put below code before the drop statement that if person table will be there it will drop the person table
      IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'Person'))
      BEGIN
      drop table person
      END
      go

    • @learnssis
      @learnssis  2 ปีที่แล้ว

      @@Maths-learn123 Okay, I will try to make another video on this topic.

  • @sonelsharma1687
    @sonelsharma1687 ปีที่แล้ว

    Hi,
    Getting error regarding parameters. Location_ID, Long,0
    Location_Name,varchar,0
    Sales_start_Date,Date,0
    Total_Sales,Long,1
    Kindly review

    • @learnssis
      @learnssis  ปีที่แล้ว

      Hi Sonel, Can you email me with all details like your query, variables screnshot and parameters screeshot to aqil33@gmail.com then I should be able to tell what is going wrong here.

  • @aniketshende4220
    @aniketshende4220 2 ปีที่แล้ว

    bhai smjha rha hai ya read kr rha hai script tu

    • @learnssis
      @learnssis  2 ปีที่แล้ว +1

      Sorry bhai, I know in some videos I was very quick, but I think if I create the videos lengthy then people also don't watch 😀

  • @mrtorque4353
    @mrtorque4353 ปีที่แล้ว

    bro ur eating words while telling i am not able to understand what ur saying

    • @learnssis
      @learnssis  ปีที่แล้ว +1

      Sorry bro, yeah this is one of my oldest video and I am too quick for it. I am trying to improve.

    • @learnssis
      @learnssis  ปีที่แล้ว

      I have created one more video recently on execute sql task you can take a look at it
      th-cam.com/video/_8nbAMHXGIQ/w-d-xo.html

    • @antwanwimberly1729
      @antwanwimberly1729 5 หลายเดือนก่อน

      @@learnssisyou are doing a phenomenal job teaching us the SSIS way. No worries!

    • @learnssis
      @learnssis  5 หลายเดือนก่อน

      @@antwanwimberly1729thank you.