How can I select query results into a temporary table using SQLKata?

179 Views Asked by At

SQLKata - select query results into temp table. Do we have any option? I tried to search documentation and looks like we dont have any option to store into temporary table.

Any suggestions would really help.

select a.name, a.id into #tmp_table from table1 a join table b on a.id =b.tid

2

There are 2 best solutions below

0
RafaelNaville On

Have you tried using ".AsInsert"? Maybe I have to change the way of doing it a little bit but I think it works.

Something like this....

var query =
new Query("#tempTable")
.AsInsert(
    new[] { "Col1", "Col2", "Col3","Col4" },
    new Query("SourceTable")
    .Select("Col1", "Col2", "Col3","Col4")
);
0
Caio Cardoso On

If you just intend to generate SQL using SQLKata, I suggest you use .SelectRaw()

Ex.:

var query = new Query("tb_example as ex").SelectRaw("ex.exe_id INTO #tmpEx")